One last shot at the Augmented Assignment PEP

Warren Focke wfocke at phoenixdsl.com
Thu Sep 14 23:37:37 CEST 2000


Steve Holden:
> I imagine that many hours of time will be wasted explaining to
> Pythion newbies on comp.lang.python why these unpleasant side-effects
> occur.

We already spend those hours explaining why 

a = [0]
b = a
b[0] = 1

changes a.


Huaiyu Zhu: 
> They look like assignment in other languages, but not at all
> like the reference-based name-binding assignment of python.

Alex Martelli:
> so-called "assignment" in Python is not really what programmers of C,
> Fortran, etc, think of as "assignment", but, actually, it's *binding* 
> [or re-binding]

Steve Holden:
> In 1.5.2 and preceding implementations we have got used to the idea that 
> a variable is, in fact, a pointer (or reference) to a value, and that if 
> we "modify the value of a variable" we are actually computing a new value 
> and then replacing the current variable's content with a reference to that 
> new value.

I've always been tempted to tell people to think of "=" as binding, not
assignment, but even in versions <= 2.0, it didn't always mean that:

a = [0]
a[0] = 1

No symbol rebinding here, although we have copied a reference.

b = array.array([0])
b[0] = 1

And here we haven't even done that.


Steve Holden:
> Yup.  I suppose the real dastardly part of the PEP is this:
>
>     "To make this possible, a number of new `hooks' are added to Python
[...]
> In other words, you have to know whether each type possesses the new
> hooks in order to be able to predict the effects of the operations.

But we already have to know how objects interpret operations in order to
predict the results.  E.g., does evaluating the expression

a + 0

mail the attack plans to the enemy before or after wiping the hard drive?


In short, the amount of time we spend explaining things to people who didn't
read the instructions, and the consistency of interpretation of "=", and what
we have to know haven't changed much.  But now some things can be expressed
more clearly, and in some cases, implemented more effieciently.

Warren Focke

-- 
Just because romance and rapture have so often served as a pretext for
curdled banality doesn't make the sentiments themselves obsolete.
 -- Michelle Goldberg



More information about the Python-list mailing list