Original post

First, let me get things straight. I’ve been long enough to understand why people would pass a pointer as an argument to a function, versus passing, say a struct. Passing by value it is.

What I don’t quite understand is if there is anything wrong with passing a struct by value, modifying the copy inside the function and returning the copy that then gets reassigned to the original variable. I’m talking about side effect free, immutable functions. Coming from other languages, this seems like a no brainer, but apparently, the preferred practice in Go is to pass and modify a pointer instead. Every piece of popular code I’ve seen, including the language spec itself does that.

It cannot be simply about copying performance. I have written tens of various benchmarks on this topic, and in none of them did passing a pointer beat significantly passing an entire struct (regardless of its size).

So what is it?