On Mon, Jul 1, 2024 at 8:12 AM Timur Sharapov <lagrange31...@gmail.com> wrote:
>
> 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.Buffer
> io.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 "Even 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?

I agree that this isn't quite right.  It may read better if we put a
paragraph break between the "even in cases" sentence and the rest.

Ian

-- 
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/CAOyqgcUj8Ku2_UFCVwRcSG0aBFo9%2BKxkEK%2BX_Jq0DHVpNd5KeA%40mail.gmail.com.

Reply via email to