4 ms·
I strongly disagree. Proper terminology is incredibly relevant. As stated in the original article, pass-by-value and pass-by-reference have well-known definit
by mpakes 17y ago
I strongly disagree. Proper terminology is incredibly relevant.
As stated in the original article, pass-by-value and pass-by-reference have well-known definitions within the computer science community. There is no ambiguity here.
When we excuse the lazy use of such terms incorrectly, we hamper the ability to communicate clearly and effectively. Please stop.
The core misunderstanding seems to be a conflation of 'pass a reference by value' and 'pass-by-reference'.
Passing a reference by value != pass-by-reference. The End. Q.E.D.
Pass-by-reference means that the compiler takes a reference of (or, getting a pointer to) the parameter passed in to the function. This is not the same as passing an existing reference (pointer) to the function (by value). Java only allows the latter (primitive types aside).
A side issue is that some developers mistakenly believe that pass-by-value roughly implies a deep copy, and thus that the 'spirit' of pass-by-reference is the avoidance of a deep copy.
I would posit that many C++ functions that operate on object parameters do so via a pointer (a.k.a. reference) passed by value, just as Java does:
void modify_my_object(MyClass *myObject) {
myObject.setName("New Name");
}
int main(void) {
MyClass *myObject = new MyObject("A Name");
modify_my_object(myObject);
// myObject.name is now "New Name"
}
This is pass-by-value, and there is no deep-copy happening there.
Just because many developers don't take advantage of (or don't understand the semantics of) pass-by-reference does not excuse ignorance of the well-known definitions of those terms.