"always passes by reference"

Martijn Faassen m.faassen at vet.uu.nl
Sun Jul 30 16:41:35 EDT 2000


(Greg Weeks) <weeks at golden.dtc.hp.com> wrote:
> Martijn Faassen (m.faassen at vet.uu.nl) wrote:
> : This seems to be where the confusion comes in. When people claim Python
> : passes by value, because the *references* are being passed by value, 
> : that seems to be just stating that the only thing the computer can pass
> : in the end is numbers. If you say that, everything is by value and references
> : are impossible, which seems to be a useless set of semantics.

> Why useless?

If you say everything is 'by value' in end because references are values
too, you're giving up the useful distinction between 'by value' and 
'by reference'; everything is 'by value'. So you can say less. So it's
a rather useless way to define the words, in my opinion.

>  It works well for me and others.  Lisp uses the same object
> model as Python, and old Lispers never bothered with this "references"
> business.  They managed fine.  And there are advantages.  For example,
> these semantics allow me to say that Perl is call-by-reference while Python
> is call-by-value, a very real distinction that IMO contributes to the
> superiority of Python.

What does 'call-by-reference' mean? I mean, as opposed to 'pass-by-reference'?

If you want to ignore the word 'reference' and call it 'address', that's
fine with me. But reference and address are in my book not too different;
'address' has a machine-connotation where reference does not (it may not
actually be implemented by memory addresses, though usually it is). 
An address in the real world is after all just a reference to a particular
house, not?

If you mean *pass* (arguments) by reference, then I'd definitely say
*Perl* is pass by value (by default), and Python is pass by reference.
I don't understand the reversal?

> I started -- or at least leapt into -- this thread because at the very
> least I think it is misleading for people to assert flatly that Python is
> call-by-reference when from another point of view that is not the case.  On
> the other hand, as much as I prefer my own viewpoint, I realize that it is
> a matter of taste, and tastes are rarely changed as a result of newsgroup
> discussions.

All names in Python are references; so you're just passing the references
to the functions when you do a function call. In that sense it's by value,
but in C you wouldn't call passing around pointers and storing them in
variables 'by value' either. You 'dereference' a pointer, for instance,
when you want actual access to the value inside it.

In Python you never have to deal with getting a pointer (reference) to 
some value and the other way around; you only deal with references and
manipulate them in some way.

Perhaps there is some other semantics for 'value' and 'reference' stemming
from another programming tradition that I'm not aware about, though.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list