Augmented Assignement (was: Re: PEP scepticism)

Paul Prescod paulp at ActiveState.com
Sat Jun 30 23:55:35 EDT 2001


Tim Peters wrote:
> 
>...
> 
> OTOH, if you're slinging mega-element conformable arrays x and y,
> 
>     x += y
> 
> is much more efficient than
> 
>     x = x + y  # creates a giant temp array
> 
> and much clearer than
> 
>     x.add_in_place(y)

It is much clearer in isolation but not when placed in the context of
the rest of the language. It has different behavior than "x = x + y"
which is what most people will think x += y means. Someone even posted
on this thread: "I don't understand what's so complicated x+=y is the
same as x = x + y".

>...
> 
> As usual in this debate, the participants aren't *themselves* confused about
> it, they're worried about people much feebler than they are.  In this
> particular case, don't be so sure that isn't an empty set <wink>.

I only became skeptical of augmented assignment when I actually ran into
someone who was confused (other than the participant in this thread!).
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook




More information about the Python-list mailing list