Coding style and Python versions (was Re: Another itertool function?)

Andrew Dalke adalke at mindspring.com
Tue Apr 29 14:41:07 EDT 2003


Aahz
> I'm a little curious why you [that's me!] didn't write this as
>
>     i += 1
>
> Any reason (i.e. still need to support 1.5.2) or just habit?  If the
> latter, why haven't you changed your habit?

Learning BASIC in my formative years has rotted my brain?

I have a plodding brain.  I like using the same constructs over
and over.  I see "i = i + 1" much more easily than "i += 1".
(Though I see "i++" quite nicely.)

It's easier for others to see the intent as well, even without
experience in a language which has "+=".

The downside of making a typo just does not exist for "i".
(BTW, for long names I often copy&paste, making typos
less likely.)  You'll need to compare those odds with the
off-chance of making a typo for "i ++ 1" or "i == 1" (slipping
on the shift key).

The only time I've used += in Python is when I really was
mutating an object in-place.  Eg, I was throwing a "parse
error at character 12" where the parse only had part of a
string so didn't know the absolute location.  Each higher
block catches the exception, += offset to it, and reraises it.

What's wrong with habits?  It's a habit that I brush my
teeth.  It's a habit that I look both ways before crossing
the street.  It's a habit that I post to c.l.py.  :)

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list