3 ms·
It may be what reference means, but just because a language has references doesn't mean that it is passing-by-reference. There are plenty of languages that allo
by lvh 10y ago
It may be what reference means, but just because a language has references doesn't mean that it is passing-by-reference. There are plenty of languages that allow actual pass-by-ref, like C++. The usual litmus test is writing a function that takes two ints (not int refs!) and they're swapped at the end. In C++, you can tell because of "int&" in the signature of the function you're calling; as opposed to plain int.
In languages with macros, you get to cheat a little, and write something that looks like the above without _really_ having those semantics. However, in languages like Lisps where your macro language is extremely powerful, you might not really miss it so much.
There is a lot of convenience in _not_ having pass-by-ref! Sometimes I feel like the ardent opposition just doesn't want to admit their favorite language is missing a feature ;-) If I call a function f(a, b), I know that a, b are still pointing at the same object in e.g. Python. That is not the case in C++ (pass-by-ref) or Lisp (arbitrary macros). Predictable language semantics make code easier to reason about. That's a good thing, and it's quite plausible that the added complexity and confusion of supporting pass-by-ref isn't worth the expressiveness.
I appreciate that the term is confusing, but it does mean something. I submit that making it mean two things would be even more confusing. If it's confusing, just say "passing (an argument) _as a reference_" which is unambiguously about what you're passing, and not how you're passing it.
- mannykannot 10y agoWhenever a word with a general meaning is adopted, and specialized, as a term of art, a double meaning is created. I get the impression that philosophy prefers to invent new words (unless it is reaching into the darkest corners of the vocabulary.) What has happened here is that the double meaning of 'reference' has caused some confusion over the term pass-by-reference, which is purely a term of art. So long as a person understands what gets passed and, especially, its implications, I am not particularly bothered by the mistaken usage.
- deleted 10y ago[deleted]
- Someone 10y ago"If I call a function f(a, b), I know that a, b are still pointing at the same object in e.g. Python." def f(x): global a a = "No, you don't" a = "I know" f(a) print a This counterexample may be far-sought, but it is a minimal version of what can easily happen in larger programs that have shared mutable state. But yes, call by reference can be confusing. It also can be very useful, though. That's why many modern languages have call by reference, but also require callers to specify it at each call site. I think that gives you the best of both worlds.