Re:Understand Go pointers
by tapirl on Wednesday April 26, 2017 @09:34AM
(#14202774)
The word "Go" is not essential in the title.
[ Parent
| on HN ]
Re:Understand Go pointers
by BoorishBears on Wednesday April 26, 2017 @09:42AM
(#14202828)
If it didn't include Go, this would barely be scratching the surface (pointer arithmetic)
I see Go's pointer as closer to C#'s ref/out than anything
I personally (emphasis intentional) consider the core distinction between "references" and "pointers" to be whether you can do pointer arithmetic on the pointers. Pointers without pointer arithmetic aren't hardly scary at all, especially in languages where there is no way to deallocate the underlying value but leave the pointer behind such that it may point to the wrong thing later, be that due to something like Rust or with GC like Go.
So personally, I think of Go as having references, but not pointers (outside of unsafe).
Of course every language community uses those terms its own way, but that seems to me to be the most broadly useful way of looking at it.
Re:Understand Go pointers
by steveklabnik on Wednesday April 26, 2017 @10:53AM
(#14203455)
I've spent a lot of time on this, working on Rust's docs, and the way I see it is that "pointer" is the most generic concept, with "reference" being a more restricted form. So all references are pointers but not all pointers are references.
Words are hard.
I agree, Go in the title is irrelevant. Otherwise, it is a decent overview of the notion of pointer, although there are many of such overviews around.
My other objection is with using code like * b++ in a text that aims to be crystal clear about a single concept (pointers). That can bring totally irrelevant questions on operator precedence and right / left associations. It would be better to say * b = 201. My 2c.
Re:Understand Go pointers
by umanwizard on Wednesday April 26, 2017 @09:56AM
(#14202941)
Your asterisk got interpreted as italicization and screwed up your post.
Thank you!
If it was pointers in general I would have expected the article to talk about pointer arithmetic, which from other comments in the thread seem to be not possible in Go.
What is the use case for pointers then? are parameters passed by value instead of by reference by default?