6 ms·
No, it is not. Prove it to me by writing a Java function which can cause a variable in the caller's scope to point to a different object. You cannot, because Ja
by colanderman 9y ago
No, it is not. Prove it to me by writing a Java function which can cause a variable in the caller's scope to point to a different object. You cannot, because Java is not pass-by-reference. C++ is, and you can do this. So are macros in many languages, and you can do this. Java is not pass-by-reference.
- lmm 9y ago> Prove it to me by writing a Java function which can cause a variable in the caller's scope to point to a different object. That's not what the term means and you know it. The difference between passing by reference and passing by value is that in the plain meaning of the words (all terms eventually come to mean their plain meanings, because language is defined by consensus): whether the called function receives a value, or a reference to the value in the caller's scope. Java is the latter (for non-primitives); you can tell because the called function can modify the value in the caller's scope. If you want a term to mean "allows changing the binding in the caller's scope", coin one, but pick words whose plain meaning matches the meaning you want.
- colanderman 9y agoNo. Pass-by-reference has meant exactly what I described, for at least 44 years, when Barbara Liskov decided it didn't apply to the calling scheme she invented, which was later inherited by Java. Read: https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sh... Specifically, "it is not call by reference because access is not given to the variables of the caller, but merely to certain objects."
- lmm 9y agoCoining a new term is the right approach if you want to draw that distinction. "Java is call by sharing" would be fine. "Java is call by value" is more wrong than "Java is call by reference".
- colanderman 9y agoGlad I could convince you.
- lmm 9y agoGlad you have to make up things that didn't happen to make yourself feel better. Wait, no, not glad. That's really tragic. I hope you're ok.
- colanderman 9y agoI don't know, "'Java is call by sharing' would be fine" looks pretty similar to my first comment on this story [1]. I thought we were on the same page. I suggest you re-read the Hacker News guidelines [2] for what constitutes acceptable discourse on this site. Your first comment to me [3] and your most recent comment demonstrate a lack of civility on your part. [1] https://news.ycombinator.com/item?id=16896221 https://news.ycombinator.com/item?id=16896221 [2] https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html [3] https://news.ycombinator.com/item?id=16896569 https://news.ycombinator.com/item?id=16896569
- lmm 9y ago> I don't know, "'Java is call by sharing' would be fine" looks pretty similar to my first comment on this story [1]. I thought we were on the same page. On that much we are. But if we are reducing it to a dichotomy of "call by reference" versus "call by value", as the original article does (which is a simplified model of the space of possibilities, but legitimate; all models are false, some are useful), then "java is call by reference" is the true statement, because java's behaviour is within the sphere of "call by reference" behaviours and very much distinct from the sphere of "call by value" behaviours. > I suggest you re-read the Hacker News guidelines [2] for what constitutes acceptable discourse on this site. Your first comment to me [3] and your most recent comment demonstrate a lack of civility on your part. You first; I've been matching your tone when replying to you, that's all.
- filleduchaos 9y agoPerhaps you should actually read up what the terms mean then, because the challenge they gave you (pretty much implementing a swap) is perhaps the quintessential explanation of the difference between pass by reference and pass by value.
- kbp 9y ago> Java is not pass-by-reference. C++ is I'm sure you know this, but just to clarify, C++ allows parameters to be specially marked so as to be passed by reference. By default, arguments are passed by value.