Apology Re: Is 'everything' a refrence or isn't it?

Ben Sizer kylotan at gmail.com
Thu Jan 5 05:59:18 EST 2006


Steven D'Aprano wrote:
>
> On reading back over my post, I realise that it might
> sound like I was mad at KraftDiner. My apologies -- I'm
> not, I feel (s)he is the victim of incorrect
> information here, not the culprit.
>
> After all, as a Python newbie, how is KraftDiner
> supposed to know that when people say "Python is call
> by reference", what they actually mean is "Um, except
> that it doesn't behave like any call by reference
> language you're likely to have used before, and
> sometimes it behaves more like call by value"?

But, if you separate the calling mechanism from the assignment
mechanism, then Python does behave like every other call by reference
language. The problem is that people expect to then be able to change
the value of the referred object with the assignment operator. It's the
assignment semantics that differ from languages such as C++ and Java,
not the calling mechanism. In C++, assignment means copying a value. In
Python, assignment means reassigning a reference.

The unfortunate problem is that people think of 'pass by reference' in
association with 'assignment is a mutating operation', when really the
2 concepts are orthogonal and Python replaces the second with
'assignment is a reference reseating operation'. The only reason I
stress this is because with this in mind, Python is consistent, as
opposed to seeming to have 2 different modes of operation.

-- 
Ben Sizer




More information about the Python-list mailing list