5 ms·
I've heard that java is both pass-by-value and reference in one class, and then heard that it was pass-by-value only in another. The difference was that the fi
by araneae 17y ago
I've heard that java is both pass-by-value and reference in one class, and then heard that it was pass-by-value only in another. The difference was that the first was at a university that primarily used java, and the second was at a university that primarily taught in C++.
The fact is the usefulness of these concepts depend on what language you're writing in. In java, where pointers aren't explicit, you need to know when you're assigning a variable a memory locale versus a value. In C++, where pointer assignment is explicit, that's not a useful concept, so pass-by-reference has a different meaning.
I honestly think we should come up with a different name for pass-by-reference the way it is used in C++. It's not like people actually write code using pass-by-reference anyway :D.
- deleted 17y ago[deleted]
- omnigoat 17y agoI do believe this is why my university teaches Java for one year, then C for the second, before you even get to glance at (C++|Python|Perl|C#|other). I'm a compiler-writer, and we don't need different names - they have well defined meanings. What we need is people to stop misusing them. You've done it yourself, because C doesn't have pass-by-reference. C++ does (ie, references...), but C does not. Stop doing it! Stop misusing those terms! You just read an article that actually spelled it out, and still misused them!
- raganwald 17y agoRedefining terms that have precise meanings into terms that have imprecise meanings based on vulgar precedent is a symptom of a pop culture. Cue Alan Kay quote in 3, 2, 1, ...
- ftl 17y ago"In the last 25 years or so, we actually got something like a pop culture, similar to what happened when television came on the scene and some of its inventors thought it would be a way of getting Shakespeare to the masses. But they forgot that you have to be more sophisticated and have more perspective to understand Shakespeare. What television was able to do was to capture people as they were. So I think the lack of a real computer science today, and the lack of real software engineering today, is partly due to this pop culture." Full conversation: http://queue.acm.org/detail.cfm?id=1039523 http://queue.acm.org/detail.cfm?id=1039523
- araneae 17y agoBlah blah blah. In Shakespeare's day, his plays were ribald entertainment for the masses. People are continuously complaining about how the old ways were better, and one is entitled to one's opinion, but the old ways are in the past and gone. Soon the last person who remembers them will be dead and there will be no one to complain about it, so what's the point?
- halo 17y agoWow, that's one of the most pretentious paragraphs I've ever read. I mean, let's use the exact same argument, swapping television for books: "In the last 25 years or so, we actually got something like a pop culture, similar to what happened when widespread literacy came on the scene and some of its perpetrators thought it would be a way of getting the Bible to the masses. But they forgot that you have to be more sophisticated and have more perspective to understand the Bible. What books were able to do was capture people as they were."
- deleted 17y ago[deleted]
- philwelch 17y agoExcept, historically that's absolutely wrong. Since the advent of printing, the Bible has been the most widely published book in the world because the masses, as they are, have historically been religious people.
- kleevr 17y agoOT: I did find it very interesting to learn that the second most popular book (up to the beginning of the twentieth century) was Euclid's The Elements after the printers were done pressing bibles.
- araneae 17y agoIf it's a symptom of pop culture, then why is Middle English different from Old English? It's a symptom of language, and it's impossible to stop.
- zb 17y agoTo answer your (clearly rhetorical) question: Because language is the ultimate pop culture medium.
- olavk 17y agoThe word 'reference' have precise meanings both when taking about references to objects in Java and when taking about pass-by-reference vs pass-by-value in function call semantics. But it is two different meanings.
- mattdawson 17y agoPython, for one, doesn't help to make the matter any clearer. In fact, Python makes it look like pass-by-reference is used, even when it isn't. For a better explanation than I could ever come up with: http://stackoverflow.com/questions/986006/python-how-do-i-pass-a-variable-by-reference/986145#986145 http://stackoverflow.com/questions/986006/python-how-do-i-pa... Just to play devil's advocate: if it looks like a duck and quacks like a duck, why would I call it anything other than "duck"? It may be technically correct to say that (in Python, at least) everything is passed by value. But if it helps someone remember that lists may be altered when passed to a function and that tuples can't, what's the real harm? Again: devil's advocate.
- olavk 17y agoIt is just the terminology that is confusing, because the word 'reference' has a different meaning when talking about parameter passing semantics, than when talking about references to objects. The Effbot suggest we call Python call semantics for 'call-by-object-reference' http://effbot.org/zone/call-by-object.htm http://effbot.org/zone/call-by-object.htm which makes it a lot clearer.
- scott_s 17y agoBecause it means they don't understand what's going on in the language runtime. That is, it betrays ignorance.
- enjo 17y agoI think it's really important to understand why tuples can't be modified and lists can. If you explain it away with something factually incorrect about pass-by-reference, your doing a real disservice to whomever you are teaching. After all, the issue here has nothing to do with parameter passing and everything to do with object design. It's important to understand that tuples are truly immutable and what the implications of that is. Misuse of tuples and lists are one of the biggest problems I see in novice (and often not so novice) python code. How often do you see someone copying tuples (often inadvertently) when list semantics are far more efficient? That stems from a fundamental misunderstanding of immutability, something that might stem from not understanding how parameters are truly passed in the language.
- rlpb 17y agoMeanings are only well-defined in their particular contexts.
- steveklabnik 17y agoIn this case, the context is "programming languages." The term has a very well-defined meaning for all lanugages.
- fauigerzigerk 17y agoI think the confusion results from the fact that people use the phrase "pass by reference" without ever explicitly stating what the referenced thing is. In the original sense of the phrase, I believe, that thing was the variable itself in the form of an alias, not the object/value that a pointer variable might be pointing to.