Apology Re: Is 'everything' a refrence or isn't it?
mwm at mired.org
Thu Jan 5 17:17:44 CET 2006
"Ben Sizer" <kylotan at gmail.com> writes:
> 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.
Exactly. The critical information is that python's assignment
statement is different from what people are used to from C/C++/etc.
While telling them that "You can't do call by reference because Python
is call by object" may be correct, it leaves out the critical
information. So they're liable to run into the same problem in a
different context - like the one the OP had.
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list