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

Comments

@komuw
Copy link
Contributor

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 this to the Unreleased milestone Oct 20, 2016

@sudotliu

This comment has been minimized.

Copy link

commented Oct 22, 2016

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Oct 22, 2016

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

@sudotliu

This comment has been minimized.

Copy link

commented Oct 22, 2016

Aha, thanks @ianlancetaylor - CL on the way.

@sudotliu

This comment has been minimized.

Copy link

commented Oct 22, 2016

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

This comment has been minimized.

Copy link

commented Oct 22, 2016

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Oct 23, 2016

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

This comment has been minimized.

Copy link
Contributor Author

commented Oct 24, 2016

all of you, thank you.

@sudotliu

This comment has been minimized.

Copy link

commented Jan 29, 2017

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

@odeke-em

This comment has been minimized.

Copy link
Member

commented Jan 29, 2017

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
Projects
None yet
6 participants
You can’t perform that action at this time.