5 ms·
Everything in Go is passed by value (i.e. copied), even the pointers. The sooner you will understand this, the less problems you will have.
by Strom 11y ago
Everything in Go is passed by value (i.e. copied), even the pointers. The sooner you will understand this, the less problems you will have.
- oconnor663 11y agoThe part that confuses me is that a lot of pointers are taken implicitly. Method receivers depend on the method definition, and maps (and interfaces?) are always pointers. So it can be hard for me to tell the difference between pass-by-value and pass-pointer-by-value.
- falcolas 11y agoThe confusing thing is that those copies are wrapped in interface wrapper types when passed into a function which uses interfaces in its function signature.
- jerf 11y agoThat's true of nearly every language. "Passed by reference" is almost non-existant in reality, there's only "Pass by value copy" and "pass by copy of the reference" in most cases. The nature of structured programming and the way parameters come in to functions all but forces this; if you have a real function call (that is, not inlined), the reference has to be a copy. There's a few interesting exceptions to this, but they're very much exceptions.