←back to thread

Go is still not good

(blog.habets.se)
644 points ustad | 2 comments | | HN request time: 0.521s | source
Show context
softwaredoug ◴[] No.44983216[source]
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.

replies(7): >>44983251 #>>44983254 #>>44983637 #>>44985983 #>>44986255 #>>44986985 #>>45002523 #
1. grey-area ◴[] No.44983254[source]
I just always use pointers for structs.
replies(1): >>44983363 #
2. nikolayasdf123 ◴[] No.44983363[source]
I 80% of time use structs. common misunderstanding: it does not reduce performance for pointer vs value receivers (Go compiler generates same code for both, no copy of struct receiver happens). most of structs are small anyways, safe to copy. Go also automatically translates value receivers and pointer receivers back-and-forth. and if I see pointer I see something that can be mutated (or very large). in fact, if I see a pointer, I think "here we go.. will it be mutated?". written 400,000 LOC in Go, rarely seeing this issue.