4 ms·
> "Pass by reference" is a specific term for a much different technique which is very rarely encountered these days. C++ isn't all that rare. I suspect we'll
by civility 8y ago
> "Pass by reference" is a specific term for a much different technique which is very rarely encountered these days.
C++ isn't all that rare.
I suspect we'll have to agree to disagree whether your definition of pass by reference is universal. Given your definition, can you name any language with calling semantics which are not pass-by-value? I mean, you're always passing the value of something (be it the actual value, the address of the memory where the data is stored, or the pointer to the string containing the name of the data in an associative array).
- minitech 8y agoPopular as it is, C++ is still a pretty special case. Not many languages have references like it. (I personally don’t use any.) int a = 5; int& b = a; b = 6; // a is now 6 Allowing an lvalue argument to be changed by a function call is something more languages support, though, like C# and VB.NET. That’s what it means to “pass by reference”. Passing a reference/pointer is an accurate description of how most languages work, which might sound similar, but is really different enough to warrant not being called that. Especially because the behaviour has nothing to do with passing: variables just work that way in general in Python, Java, JavaScript, Ruby, C#, VB.NET, Lua, …. Anyway, back to: > I may be missing something, but I can't find any example in my mind which indicates difference between passing in Java and Python. You’re right that C extensions can break the rules, but in the real world they don’t (because that breaks everything); immutable int objects are effectively primitives. (Modern JavaScript – in strict mode – is an example of a language that hides the implementation details of primitives better than Java.)
- baddox 8y agoI don’t know any C++, so forgive me. I can’t name any language that doesn’t use pass by value. Okay, I’ve heard that FORTRAN does, but I’m not sure. But that’s the point. The distinction was made when both techniques were popular, since it was obviously an important distinction to understand.
- mark-r 8y agoEarly FORTRAN programs could break if you passed a constant into a function and reassigned the value within that function, because the constant would change.