[Python-Dev] Augmented assignment

Peter Funk pf@artcom-gmbh.de
Thu, 15 Jun 2000 23:30:45 +0200 (MEST)


Hi!

Thomas Wouters:
> I'd like some (minor) feedback on the augmented assignment thing I'm working
> on. I understand Guido is the only one who accepts patches like this, and
> appreciate that, but I'm hoping someone can at least tell me what I'm doing
> wrong so I can fix it before Guido sees it ;-) But if I'm being an impatient
> flap, just tell me so and I'll calm down.

Disclaimer: The following is only *my* personal opinion.
But since you have asked for it. ;-)

I don't like this augmented assignment syntax at all! (independent 
from your particular implementation, which I didn't had a look at).  

Augmented assignments are unPythonic because they don't add any new 
functionality to the language.  From what I've seen, all people, 
who ever missed it, were experienced C-programmers.  And C shows 
its inheritance from various assembler languages in its 
augmented assignment and its ++pre and post increment++ and decrement--
operators.  Many of these features were born in the 70s of the
last century:  At that time optimizing was very important and 
compilers were relatively dumb.  This applies in no way to the
situation we have today with Python.

What remains is, that augmented assignments are only a short cut
notation, which introduces more variability to express the same
algorithms and so they hurt readability.  This feature must be learned
additionally, where normal assignment are easiely understood from
school mathematics.  It also introduces many more possibilities to make
subtle mistakes, since it is not obvious (at least to No-C-programmers)
when and how often the index expression will be valuated.  Look at
the following example:

        class Bar:
	    def __init__(self):
	        self.val = 0
	    def __call__(self):
	        self.val = self.val + 1
		return self.val
	bar = Bar()
	foo = range(4)
and than
	foo[bar()] = foo[bar()] + bar()
	print foo
versus
	foo[bar()] += bar()
	print foo

Todays Python forces the programmer to explicitly say, what should happen.

So I think these +=,-=,*= features are evil.  In the same sense as macro
preprocessors are evil in 'C' and 'from module import *' is already evil
in Python.  Add more and more of this stuff and you end up on the dark 
side of programming.

If augmented assignments will ever become part of Python, I would at least
like to see a strong recommendation added to the styleguide not to use 
this feature.

Enough with this rant.

Regards, Peter
-- 
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)