Augmented Assignement (was: Re: PEP scepticism)

Rainer Deyke root at rainerdeyke.com
Sat Jun 30 15:19:28 EDT 2001


"Carlos Ribeiro" <cribeiro at mail.inet.com.br> wrote in message
news:mailman.993927046.4577.python-list at python.org...
> As the current discussion about Augmented Assignment stands, I was
> wondering if it was not better to make it invalid to use augmented
> assignment on immutable types.

Bad idea.  If anything, I would go the other direction and make it illegal
for mutable types.  In my experience, the primary use of augmented
assignment is for integers:

a += 1

vs.

a = a + 1

The augmented assignment version is clearly more maintainable since it
contains less redundancy.  On the other hand, augmented assignment is
redundant for mutable types.  If I want to extend a list in place, I'll use
the 'extend' method since it more clearly communicates my intent.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list