3 ms·
The key feature of pass-by-reference is whether the callee can replace the value bound to the caller's argument (not mutate it). In other words, pseudocoded:
by geoelectric 9y ago
The key feature of pass-by-reference is whether the callee can replace the value bound to the caller's argument (not mutate it).
In other words, pseudocoded:
x=1
changeMe(x)
write(x) // 2
With that in mind, it's clearer that JS is pass-by-value with object reference values (or pass-by-sharing, though I never hear that in practice) as the caller remains bound to the passed object, but a C++ reference argument is an actual pass-by-reference of the original binding. So's an argument passed to a Pascal/Delphi out or variable parameter, and I'm sure other examples exist as well.
So I guess it depends on what you mean by "nowadays" but I'd still consider C++ a modern language within "everything".
- quicknir 9y agoYou can never actually replace what the reference is bound to in C++, you can only call the assignment operator. The real distinction here is that in languages like Java and python, assignment is fundamentally different from mutation. In C++ there is no distinction, assignment is just a form of mutation.
- deleted 9y ago[deleted]