-
Notifications
You must be signed in to change notification settings - Fork 18k
tour: clarify when to use pointer receivers #17524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Where does the |
The tour is in golang.org/x/tour. |
Aha, thanks @ianlancetaylor - CL on the way. |
This is my first contribution to any of the Go projects. Who is assignment of the issue up to? Do people generally just self-assign once they have a patch ready? If anyone here knows how that workflow goes, please let me know. |
CL https://golang.org/cl/31728 mentions this issue. |
We don't use the "assignees" of these issues very seriously. It's sufficient to leave a comment saying that you have sent a CL, as you did. Thanks. |
all of you, thank you. |
Can anyone recommend another reviewer here? I got a +1 but seems like we need at least one more? |
I've pinged @campoy on the Gerrit CL. |
There appears to be a confusion (at least to me) on what the appropriate receiver type ought to be by default.
Looking at; https://tour.golang.org/methods/8
That tutorial encourages new go users that:
There are two reasons to use a pointer receiver.
The first is so that the method can modify the value that its receiver points to.
The second is to avoid copying the value on each method call.
this seems to imply that you should default to using pointer receivers in only those two cases.
whereas looking at; https://github.com/golang/go/wiki/CodeReviewComments#receiver-type and a few other credible go sources eg; https://twitter.com/rob_pike/status/788743046280077313
we see that actually, pointer receivers should be the default while value receivers are the exception.
So to summarize; the tour.golang notes makes it appear as if pointer receivers are the exception(that was my impression when I went through those notes as a new go user some months back) whereas in actual sense they are (or ought to be) the default.
The text was updated successfully, but these errors were encountered: