4 ms·
The problem is that you can still mutate a copy. But does the person mutating the copy realize it's a copy, and that it won't propagate? It's also hard to keep
by kevinmgranger 4y ago
The problem is that you can still mutate a copy. But does the person mutating the copy realize it's a copy, and that it won't propagate?
It's also hard to keep a mental model of which builtin primitives are values (copy semantics) and which are references (reference semantics).
Arrays are values. Slices are references, but might be a reference to some dynamically allocated slice or an array. Appending to a slice makes a copy _of the slice_, but which might modify the array it came from. It's not possible to tell from the type if it references an array or not.
Maps have reference semantics too. Why is it that maps and slices are the only references that don't have a pointer star to denote that?