total idiot question: +=, .=, etc...

Reimer Behrends behrends at cse.msu.edu
Wed Jun 23 01:22:49 EDT 1999


Preston Landers (planders at mail.utexas.edu) wrote:
> Can someone *please* give me a good reason why Python doesn't yet have 
> +=, -=, and .= and other such operators?  I know it's just syntactic
> sugar, but damn, it is such sweet sugar!

Few people, I think, have ever tried to objectively count how often such
a construct is used. The Python 1.5.2 source, for instance, has
approximately one of ++, --, +=, -=, *=, /= every 40 lines. If you do
not count the occurrences if ++ and -- in for loops, for which there's a
construct in Python anyway, you can roughly double that number. Now, C
is not Python, but it's a good first-order approximation of how often
you need it--the Python source is one of the cleanest C programs I know
of.

Personally, I can easily live without a construct that I can use on
average once every three screens of code or so. On the other hand, I
_am_ getting pretty sick of having to type self.whatever countless
times, where pretty much any other language allows me to discard the
"self." part. Not only is it annoying to type, it also reduces the
readability of OO code a lot, much like the gratuitious use of
punctuation characters as variable prefixes in Perl does.

Among all the suggestions for Python 2.0, removing the necessity of
prefixing methods and instance variables with "self." (and not having
to list it as an argument, either) would be my #1 wish.

[...]

				Reimer Behrends




More information about the Python-list mailing list