In most golang codebases I look, people are using types by reference:
type Foo struct {}
myFoo := &Foo{}
I usually take the opposite approach, passing everything as copy and only pass by reference when I want to perform something destructive on the value, which allows me to easily spot destructive functions (and which is fairly rare).
But seeing how references are commonplace, I guess it's not just a matter of taste. I get there's a cost in duplicating values, is it that much of a game changer? Or are there other reasons why references are preferred?
It would be great if someone could point me to an article or documentation about why references are preferred.
Thanks!
Foos, and placed these values into several distinct containers (say, slices) copying them by value. This means each container now has a copy of each of the source value, and changing each of them in any of these containers will not have any effect on the others. Sometimes it's okay, sometimes it's not. In each case you should think what semantics you want to put to the values of a type you're creating and how do you intend to use values of that type.append( myslice, &myItem ), though?