▲ | softwaredoug 4 days ago | |||||||
I like Go, but my main annoyance is deciding when to use a pointer or not use a pointer as variable/receiver/argument. And if its an interface variable, it has a pointer to the concrete instance in the interface 'struct'. Some things are canonically passed as pointers like contexts. It just feels sloppy and I'm worried I'm going to make a mistake. | ||||||||
▲ | looshch 2 days ago | parent | next [-] | |||||||
> my main annoyance is deciding when to use a pointer or not use a pointer as variable/receiver/argument i think you can take these[1][2][3][4] official advices and extrapolate to other cases [1] https://go.dev/wiki/CodeReviewComments#receiver-type [2] https://google.github.io/styleguide/go/decisions#receiver-ty... | ||||||||
▲ | RadiozRadioz 3 days ago | parent | prev | next [-] | |||||||
This confused me too. It is tricky because sometimes it's more performant to copy the data rather than use a pointer, and there's not a clear boundary as to when that is the case. The advice I was given was "profile your code and make your decision data-driven". That didn't make me happy. Now I always use pointers consistently for the readability. | ||||||||
▲ | empath75 3 days ago | parent | prev | next [-] | |||||||
Using pointers as optional types is the absolute worst part of using go. | ||||||||
▲ | aatd86 3 days ago | parent | prev | next [-] | |||||||
I mostly use it as a signal for mutability to some extent. And also when I want a value with stable identity I'd use a pointer. | ||||||||
▲ | vbezhenar 4 days ago | parent | prev | next [-] | |||||||
Just use pointers everywhere? Who cares. | ||||||||
| ||||||||
▲ | spicyusername 4 days ago | parent | prev | next [-] | |||||||
...do you want a copy or the original object? | ||||||||
| ||||||||
▲ | grey-area 4 days ago | parent | prev [-] | |||||||
I just always use pointers for structs. | ||||||||
|