Chris Smith said:
Andreas Leitgeb wrote: [ SNIP ]
By the (at least as "very") definition of "reference" alone, one might
expect different behaviour of Java already. No matter if it is passed or
not. Java doesn't really have "references" the way C++ has.
I'm not sure what C++ has to do with this.
There really isn't a widely used definition of a reference. The word is
used differently by different languages, and it's best to just adopt the
definition from the language in question. C++ means one thing; Java
another; CAML yet another. On the other hand, pass-by-reference is a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
concept with a well-understood definition.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Namely: the lvalue of the
formal parameter is the same as the lvalue of the actual parameter.
[ SNIP ]
Apparently not so well-understood, Chris, not if we (and tens of thousands,
and hundreds of thousands, and millions, of others) are having this
discussion. I spent the past few days doing some fairly intense research
(Googling) on pass by reference, pass by value (also keywords "call by ...",
"pointer", "evaluation strategy", etc etc) and so forth. I tried to
categorize sources as summary and explanatory: "summary" sources had a quick
definition of a term used in this thread, and "explanatory" sources actually
had some discussion of the topics. Naturally I also applied some measure of
quality control, without trying to apply a personal bias based on my own
perspective (which has already been expressed).
(Note: I'll use PBV and PBR to abbreviate "pass by value" and "pass by
reference".)
And the fact is, "call/pass by value/reference" is _not_ something with a
well-understood definition, not when it comes to categorizing things like
"pass pointer by value". Like it or not, while people do understand PBV to
mean copying the value of the actual argument into the formal parameter
variable, they (myself included) also make a difference between that actual
argument being the thing of interest (a primitive or object) or being a
reference to the thing of interest.
I'd like to think that most folks, including everyone participating in this
thread, grasps the difference between passing a pointer by value and passing
a reference...the swap() function example, so to speak. In one you can
actually change the value of the thing passed as it visible in the caller,
and in the other you cannot. Yes, you can use pointers to modify the value
of the thing pointed at, in the calling code, but that's still not modifying
the actual parameter passed (the pointer) as it exists in the calling code.
However, lots of people (again, myself included) do describe "passing a
pointer by value" as PBR, insofar as being able to modify the pointed-to
thing is very often described as PBR. And the reason this terminology is
common because when passing a pointer by value you do in fact have a
reference to the object. I'm trying not to be argumentative here, I'm just
pointing out (pun not intended) that there are at least two different usages
of the word "reference" here, one somewhat less technically precise than the
other, but both are (arguably) valid. It depends on the context.
I myself am perfectly happy to use the more precise language to keep Java
people happy - it's no sweat off my back. But equally well I'm not going to
correct a C programmer who says "pass by reference" (when it's "pass pointer
by value") when he clearly knows what it is he or she is doing.
AHS