I'm kinda reluctant to jump into this fray, but it's Friday afternoon and I
don't want to answer my phone...   This is such an OLD argument, I'm a
little surprised to see it surface again.  I'm probably going to say the
same thing, too many different ways, so I'll apologize now.

On Friday, 05/31/2002 at 01:02 MST, a correspondent wrote:
> In Java, pass by reference works about the same as in any other
> language.

Um, err...  A couple of points:

First, you can't use the phrase "as in any other language" -- there are
just too many languages, that do things too differently, for that to ever
be true.

Next, (again), Java does *not* do pass-by-reference -- all parameters
(including references) are pass-by-value -- just like C.

The distinction between pass-by-value and pass-by-reference is based on
what gets put into the parameter area of the stack frame -- in Java it's
ALWAYS the value itself -- it is NEVER the "address" of the value.

By way of contrast, consider a language that provides both schemes, such as
Modula-2 or Pascal.  Implicitly taking/passing the address of a parameter
-- as is done with the VAR parameter construct -- is "passing by
reference."  In "pass-by-reference" you don't _have_ to explicitly take the
address of something and pass that -- the "address-taking" is done
automatically.

Again, passing a pointer in C is NOT the same thing as "pass-by-reference"
-- after all, it is the value of the pointer that is passed, not its
address.  (Sure, you can use that pointer to mess around with the storage
it points to, but changes to the pointer itself are NOT reflected in the
caller's actual parameter pointer.)

Pass-by-reference is a common (and effective) construct for manipulating
"common blocks" of storage, without incurring the overhead of
passing/returning the "block" itself by value.

> When an object is passed to a method, the reference (address)
> is given to the method.  The method may directly manipulate the
> reference if it desires, but it does not directly manipulate the object
> itself.

IMHO, blurring the distinction between reference and "address" is
counter-productive in a Java discussion.  Addresses are nasty, dirty,
smelly, evil things that rarely even bathe.  References, on the other hand,
are the very "stuff" constituting long life, assured happiness, and
abundant virility.

OK, maybe I overdid that last bit.

Sure, we all know that references are implemented with 'pointers' and
'addresses' and other such gorp...  My argument is, simply, that lowering
ourselves to that level leaves us only inches above malloc/free, where only
insane masochists (like Alan W., apparently :-) want to tread.  <shudder>

OK, I'll shut up now.

-blair

Blair Wyman -- iSeries JVM -- (507) 253-2891
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"It is a sobering thought that when Mozart was my age,
he had been dead for two years." -- Tom Lehrer




To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to