[Python-Dev] Augmented assignment
Peter Funk
pf@artcom-gmbh.de
Fri, 16 Jun 2000 09:11:57 +0200 (MEST)
Hi,
[...]
[me]:
> > 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.
[Gordon McMillan]:
> It definitely *improves* the readability of incrementing very-long-
> expression. Just not to the point of readability ;-).
I agree, that very complicated multidimensional expressions, (possible
mixing tuples, lists, dicts and computations) are even more errorprone
, if you have to repeat them twice just to increment an element.
But than you would use an helper variable to hold the index expression
anyway.
example:
foo = range(3); bar = range(3); cols = ('red', 'green', 'blue')
chans = {'red':2, 'green':1, 'blue':0}
foo[chans[cols[2-bar[0]]]] = foo[chans[cols[2-bar[0]]]] + 1
is indeed ugly. But
i = chans[cols[2-bar[0]]]; foo[i] = foo[i] + 1
is at least just as (un)readable as
foo[chans[cols[bar[0]]]] += 1
with the exception, that even newbies get a chance to figure out,
what the former line is supposed to do without having to read a language
reference manual telling them something about augmented assignments.
But you are right: This has been discussed often enough on c.l.p.
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)