Google's style guide is a popular reference for Go programmers. In it, they 
list off a number of scenarios where one would use a value receiver vs a 
pointer receiver. But, ultimately, they end the list with "when in doubt, 
use a pointer receiver".

In my experience, I've noticed the majority of Go programmers I encounter 
default to using pointer receivers in all circumstances. And I have a hard 
time justifying any protest because the scenarios typically don't fall into 
the "approved" set where value receivers are recommended.

I also notice that my IDE (GoLand) defaults to returning a pointer to a 
struct when I use its "Generate Constructor" auto-complete functionality. I 
can't help but suspect this was motivated by the "when in doubt" advice 
from Google.

I'd be curious to hear thoughts on this topic. I tend to advise developers 
to default to value receivers because I perceive benefits to avoiding nil 
pointer exceptions. But it's hard to substantiate my advice as anything 
idiomatic.

-- 
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/0f45d769-2f8d-49e3-85e4-3b2f46c8ac42n%40googlegroups.com.

Reply via email to