2 ms·
What are you on about? Java, Python, Ruby, C#, JavaScript, most languages used to day have reference semantics for objects.
by eptcyka 4y ago
What are you on about? Java, Python, Ruby, C#, JavaScript, most languages used to day have reference semantics for objects.
- bin_bash 4y agoI don't think any of the languages you mentioned support true pass-by-reference. (maybe C# and Java, but it's not common) I've heard what you're describing as "pass-by-value-reference" Go, however, supports pass-by-reference which allows you to write a function like this: func swap(x *int, y *int) { var temp int temp = *x /* save the value at address x */ *x = *y /* put y into x */ *y = temp /* put temp into y */ }
- eptcyka 4y agoSure, you can't have the same code for Python, for instance, even if it was using objects, but you can have the same effect using a hack by copying the __dict__ from one object to another. However, you are still passing the object to a function by reference because the function can mutate the object and the object that the callee passed will also be mutated the same way, i.e. mutable objects are passed by reference, and values are passed as values. Which is how python, javascript, Java and the rest work. Obviously, you don't get to change what the reference is pointing to in most of these languages, but you can change the value that is being pointed to.