Augmented Assignement (was: Re: PEP scepticism)

Paul Prescod paulp at ActiveState.com
Mon Jul 2 10:10:41 EDT 2001


Thomas Wouters wrote:
> 
> On Mon, Jul 02, 2001 at 06:15:10AM +0000, Courageous wrote:
> 
> > x += (1,2,3)
> 
> > ... is not the same as...
> 
> > x=x+(1,2,3)
> 
> > That's just plain wrong.
> 
> No, that's the *whole intent* of the thing. If x += y was supposed to be
> *exactly* the same as x = x + y, it would have been spelled as 'x = x + y'.
> It isn't, and it's not. It's not supposed to be syntactic sugar for normal
> addition, it's supposed to be syntactic sugar for a method call.

That's exactly the problem. The millions of newbies who begged for this
feature didn't want a short form for a method call. They wanted a short
form for a repetitive assignment pattern. The feature as implemented
tries to make them happy and at the same time tries to make the NumPy
guys happy. If we had chosen to ONLY make the NumPy guys happy then the
feature would never have got in -- after all it is isomorphic to a
method call. I think the newbies were sacrificed on the alter of the
Numeric Dieties.

I'd like to see some real-world code that takes advantage of the fact
that this single operator behaves differently with mutable and immutable
types. Then I will believe that it isn't just a squishing together of
two unrelated features.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list