4 ms·
> "Pass-by-reference: The formal parameter merely acts as an alias for the actual parameter." "Alias" means nothing to a CPU, nor is it an ABI. At the core, pa
by xtrapolate 8y ago
> "Pass-by-reference: The formal parameter merely acts as an alias for the actual parameter."
"Alias" means nothing to a CPU, nor is it an ABI. At the core, passing by reference is usually implemented by providing the "address-of" something to a function (for example). The "address-of" itself, is passed by value. Going by that logic, everything everywhere is passed by value.
- asfasgasg 8y agoThis 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 8y 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 8y 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 8y 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 8y 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 8y 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 8y 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.
- chrisseaton 8y ago> "Alias" means nothing to a CPU, nor is it an ABI. But the language isn't defined in terms of a CPU. It's defined in terms of abstract semantic rules. You shouldn't think about implementation, especially at the CPU level, when talking about semantics. The idea is that the alias is implicit in pass-by-reference. It isn't implicit in pass-by-value. How you implement that alias is irrelevant for discussion at this level.
- xtrapolate 8y ago> "But the language isn't defined in terms of a CPU." I disagree. I submit the whole reason we pass objects by reference or by value in the first place, has much more to do with conserving computational resources/reducing runtime, than with providing abstract programming semantics for software developers.