Concept | Java | Python | Go | C | C++ |
---|---|---|---|---|---|
Primitives | Pass-by-value | Pass-by-value (immutable) | Pass-by-value | Pass-by-value | Pass-by-value |
Objects | Reference passed by value | Reference passed by value (mutable objects can be modified) | Structs passed by value | Structs passed by value | Can be passed by value or reference (&) |
Arrays | Reference passed by value | Reference passed by value (mutable lists/tuples) | Slice header passed by value | Passed as pointer (int arr[]) | Passed as pointer or reference (int &arr) |
Pointers | Implicit (references) | Implicit (everything is an object reference) | Explicit (*T) | Explicit (*) | Explicit (*), but references (&) preferred |
Formerly trained more "hands-on" languages like C, C++ and Java, where worrying about pointers, references, garbage collection and pass-by-value/pointer/reference, and eventually shifted to Python for AI/ML-centric software development.
If you're passing a struct by value, you shouldn't expect to be able to modify the struct in any function calls; whereas if you're passing the struct by pointer, that should be expected. Hence when combining with interfaces, the method sets (functions "inherited") of struct addresses should include function that indicate both struct and struct pointers in the receiver, whereas structs only inherit functions with struct receivers. (safety accorded through the interface)
When doing manual calls outside of interfaces, it resolves automatically to allow it either way (oversight is given to the programmer, somewhat like editing dictionaries in Python)
More to come...