6 ms·
This is the answer. Under the definition proposed in the article, all languages where the "=" operator can copy the values inside referents are "pass-by-referen
by asfasgasg 9y ago
This is the answer. Under the definition proposed in the article, all languages where the "=" operator can copy the values inside referents are "pass-by-reference." Languages where the "=" operator lacks that capability are pass by value. That is the only difference between swap in java and c++. In C++, operator= is a method over the value of the referent. In Java, you have to explicitly call that method. IMO it is a useless definition of "pass-by-reference," but the author is entitled to it.
(With the exception of primitives. I guess that's the real rub -- Java's special casing of primitive values.)
- colanderman 9y agoIt is literally the definition of pass-by-reference. Your opinion does not change it. By the way, there is at least one additional difference in languages like Python and JavaScript with dynamic variable (not value) scope. In those languages, you can `delete` a variable, which removes the binding from the scope. Pass-by-reference would mean that you could delete a variable from a non-local scope if the variable were passed by reference. (This is not the case; `delete` in these languages merely deleted the local variable binding, as it ought, given that they are pass-by-value.)
- lmm 9y ago> It is literally the definition of pass-by-reference. Your opinion does not change it. Who died and made you secretary of the Académie anglaise? Language is defined by consensus; a word means x only to the extent that it is understood to mean x by both the sender and the receiver. This whole thread makes it pretty clear that "pass-by-reference" does not draw the distinction that you think it draws; if you want to draw those distinctions, find words that clearly draw those distinctions. Words are tools for communication, not ends in themselves.
- colanderman 9y agoI've been working in the field of language translation in and out of academia for over a decade. I think that makes me pretty qualified to communicate the definition as used in standard literature. English language usage has no bearing on technical terms, your snark notwithstanding.
- jack9 9y agohttps://en.wikipedia.org/wiki/Reference_(C%2B%2B) https://en.wikipedia.org/wiki/Reference_(C%2B%2B) https://courses.washington.edu/css342/zander/css332/passby.html https://courses.washington.edu/css342/zander/css332/passby.h... I mean, it's not hard to take a look at what was already decided.
- asfasgasg 9y ago> In pass by reference (also called pass by address), a copy of the address of the actual parameter is stored. Use pass by reference when you are changing the parameter passed in by the client program. Your understanding of "what has already been decided" is contradicted by your second link. Under the definition there, Java is pass by reference except for primitives -- i.e. it is contra the "Java is Pass-by-Value" article. (I suppose you could say that "the actual parameter" is not the referent object, but the pointer to it in the frame of the caller function. But I'm not aware of any definition of "actual parameter" that would allow you to impose that interpretation on others -- it's a vague term. I'd further argue that that interpretation is pretty convoluted, which might be why few languages other than C++ use it. Anyway, "the actual parameter" could mean the referent or the pointer to the referent depending on how you're modeling the program.)
- colanderman 9y agoNo. If Java were pass-by-reference a function could cause the caller's reference to point to an entirely different object. That is, yes, the implementation must pass a pointer which points into the caller's frame. This is what happens with C++ references. This is not what happens with Java arguments.