3 ms·
Yes I understand what the pointer means I'm just surprised they would default to that or generally encourage it (again I don't know the language that well but i
by agentgt 9y ago
Yes I understand what the pointer means I'm just surprised they would default to that or generally encourage it (again I don't know the language that well but it appears pass by value is not used often for I guess performance reasons). I probably just haven't looked at the right libraries or programming practices in Golang but it appears most APIs are very much mutable and thus use pointers.
With Java (and lets assume Java now has Value types for argument sake) the default is immutable references but the language could easily provide other reference types (and in fact sort of does) that would allow pointer like behavior and value like behavior. And with immutable references the runtime may actually copy anyway for some types (I vaguely remember the JVM doing this somewhere).
The reason I don't mind pointers in Rust or C/C++ is that I expect to manage the memory because the languages doesn't do the memory management.
- pokstad 9y agoThe language doesn't really have a preference for either. When you see it being done mostly with pointers that's usually the author's preference. Also, using a pointer for a receiver is more convenient than pass by value since you can always derive the value by dereferencing a pointer, but you cannot derive the original pointer after a value has been passed by value (since the address has changed during the copy operation).