Skip to content
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

tour: clarify when to use pointer receivers #17524

Open
komuw opened this issue Oct 20, 2016 · 9 comments
Open

tour: clarify when to use pointer receivers #17524

komuw opened this issue Oct 20, 2016 · 9 comments
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@komuw
Copy link
Contributor

komuw commented Oct 20, 2016

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.

@quentinmit quentinmit changed the title tour.golang docs confusion about receiver types. tour: clarify when to use pointer receivers Oct 20, 2016
@quentinmit quentinmit added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Oct 20, 2016
@quentinmit quentinmit added this to the Unreleased milestone Oct 20, 2016
@sudotliu
Copy link

Where does the tour code live? This doesn't appear to be part of the main go codebase.

@ianlancetaylor
Copy link
Contributor

The tour is in golang.org/x/tour.

@sudotliu
Copy link

Aha, thanks @ianlancetaylor - CL on the way.

@sudotliu
Copy link

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.

@gopherbot
Copy link

CL https://golang.org/cl/31728 mentions this issue.

@ianlancetaylor
Copy link
Contributor

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.

@komuw
Copy link
Contributor Author

komuw commented Oct 24, 2016

all of you, thank you.

@sudotliu
Copy link

Can anyone recommend another reviewer here? I got a +1 but seems like we need at least one more?

@odeke-em
Copy link
Member

I've pinged @campoy on the Gerrit CL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants