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

Michael Hudson mwh21 at cam.ac.uk
Wed Jun 23 02:58:14 EDT 1999


behrends at cse.msu.edu (Reimer Behrends) writes:

> 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.

I sometimes think this when writing Python; but in my summer job which
I've just started, I'm frequently faced with large screenfulls of C++
and not being able to tell whether a given variable is local, static,
class or global at a glance is mightily annoying. 

Just my humble opinion.
Michael
 
> 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