https://go.dev/doc/faq#different_method_sets

I am referring to this paragraph that in my opinion answers one of the 
trickiest questions for new Go developers. 





*Even in cases where the compiler could take the address of a value to pass 
to the method, if the method modifies the value the changes will be lost in 
the caller. As an example, if the Write method of bytes.Buffer used a value 
receiver rather than a pointer, this code:var buf bytes.Bufferio.Copy(buf, 
os.Stdin)would copy standard input into a copy of buf, not into buf itself. 
This is almost never the desired behavior.*

Even though I understand the explanation, I think that it's a bit unclear. 
If the Write method used a value receiver, then the whole example doesn't 
make sense and the part "E*ven in cases where the compiler could take the 
address of a value" *doesn't apply at all because the code works as is, and 
the compiler doesn't really have to take any addresses. 

My bet is that the document meant "if the code above worked..."

What do you think? 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/31623bcd-8902-450b-8498-147ac00e5e06n%40googlegroups.com.

Reply via email to