PATCH: Augmented assignment

Charles Boncelet boncelet at udel.edu
Tue Jun 13 20:20:45 EDT 2000


David wrote:
> 
> On Fri, 9 Jun 2000 16:39:38 +0200, Thomas Wouters <thomas at xs4all.net>
> wrote:
> 
> >As promised, here is my patch to add augmented assignment (+=, -= and
> >family) to Python. It's still Work In Progress, and probably requires a
> >rewrite of some magnitude before Guido will accept it.
> 
> Why would the Python community want this?  It obfuscates code, in as much
> that newbies aren't likely to intuite what the symbols mean.

I, for one, think the patch idea is great and hope it gets added 
immediately.

It is important that Python be accessible to newcomers, but it also 
must be convenient to experts as well.  It does little good if 
newcomers learn Python, then move on to a more convenient/powerful
language.

For instance, I just finished some code that did a lot of
>>>self.array[index] = self.array[index] + 1

I would have loved to be able to type
>>>self.array[index] += 1
instead.  My code wasn't causing any side effects, so that's not the
issue.  The issue is I didn't like typing all those symbols.  (I'm
sorry,
but I don't like typing and I expect I'm not alone. I like that I don't
have to type those silly braces other languages require. :-)

I know there are plenty of languages that allow the "+=" construct. 
That Python lacks it is not enough to cause me to change, but it may
cause
others to, or, more likely, cause them to never pick up the language.
 
>
> And it's not like it adds new functionality nor improves code readibility.
> It just saves the lazy programmer a whopping one or two keystrokes.

As others have pointed out, it does add functionality.  For example, 
awhile back Tim Peters pointed out that x = x+1 can be much slower than
x += 1 for large matrices.  And, in my opinion, it does improve
readability.

------
Charles Boncelet, University of Delaware, <boncelet at udel.edu>
On sabbatical at ADFA, Canberra Australia, <boncelet at ee.adfa.edu.au>
Home Page: http://www.ece.udel.edu/~boncelet/



More information about the Python-list mailing list