Compound Assignment Operators ( +=, *=, etc...)
gmcm at hypernet.com
Sat Aug 14 22:36:07 CEST 1999
[posted & mailed]
> Mostly it's the old "burnt child fears fire" syndrome. Or, if you
> would, "fool me once, shame on you; fool me twice, shame on me". By
> outlawing it, you can't get burned/fooled by it.
Right. It is part of Python's stated goals to be "safe as milk" under
normal usage. (Obviously, all bets are off as soon as you override
__setattr__, or play with metaclasses).
> As to why there's no x++ there, consider how often people from a
> Pascal(ish) background are confused between x+1 and x++ and ++x, and
> you'll begin to see what kind of problems caused it to be vetoed.
Additional point: If x++ were taken as syntactic sugar, it would have
the odd affect of modifying a name binding in place.
If more than syntactic sugar, it would do different things depending
on whether x was mutable or immutable.
No telling whether either of those would become major conceptual
stumbling blocks without experimentation. While I like both those
shortcuts, there are certainly more interesting things to experiment
> But the best reason is probably the one another poster already
> supplied: because Guido didn't like them. An interesting study
> would be to check the extent to which he also forbids such
> constructs in his own C code. :-)
As you probably expected, when Guido writes C, he writes C.
More information about the Python-list