passing by refference

Alex Martelli aleax at aleax.it
Sat May 17 05:14:32 EDT 2003


Aahz wrote:

> In article <873cjfbrxd.fsf at charter.net>,
> Doug Quale  <quale1 at charter.net> wrote:
>>
>>Argument passing in Java and C are no different from Python.
> 
> At the technical level, that's correct, provided you define "argument"
> correctly.  But because assignment does different things in Python, too
> many Java/C programmers get confused with Python's semantics.

C, sure.  But I don't see how a Java programmer could possibly be
confused by Python's semantics for assignment and argument passing:
they're exactly parallel to the ones Java uses for all types that
subclass Object -- Java special-cases a few "lower-level" types such 
as int, but it's even difficult to show where that makes any
difference (apart from having to wrap int &c in Java if you want
to hold them in a Vector, and the like).


> In C, you have this:
> 
>     myStruct a, b;
>     a.x = 1;
>     b = a;
>     a.x = 2;
>     print ("%d\n", b.x);
> 
> There's simply nowhere in Python that assignment performs a value copy
> that way.  

And how would Java reproduce the C "implicit value copy" behavior, either?

> Using "value" to describe both the references to objects and
> to the objects themselves is too confusing.  Therefore "call-by-value"
> is confusing and should be avoided when discussing Python.

I absolutely agree with you here.  But I think it's just as confusing
for Java even though many (not all) writers and teachers tend to use
such confusing terminology in that case.


Alex





More information about the Python-list mailing list