Is current integer for-loop syntax a wart?

Laura Creighton lac at strakt.com
Sat Mar 9 13:35:29 EST 2002


> The second complain is significant (I think). That is the following:
>         for i in range(len(mySequence)):
> This is something that I use all the time, and more relevently it is 
> something that BEGINNERS use all the time. 

Interesting.  Do you mean 'beginners who have never programmed before'
or 'beginners who have lots of habits from other languages'.  I need
actual hard index numbers like this rather rarely - mostly as arguments
to the Tkinter grid window manager to tell it which column to grid
my widget.  And even then I find it easier to use zip.

There are some people who really, really, really hate using

while 1:
   break on some condition

they go crazy actually trying to calculate all the times when they
should be in a loop rather than the more straightforward calculation
of when it is time to leave.  

Since you mention Java, I wonder if overcoming this habit is a common
labour for Java programmers that are learning python - moreso than
those who have come from other languages.  It would be fun to run some
tests.  I can't provide any datapoints -- it's the Smalltalk I have
to take out of my python.  I liked PEP 276 because I like the idea
of integer iteration.  But I have deep suspicions that this indicates
that there is something wrong with me, not that there is something 
wrong with the people who do not like the idea at all.

Laura Creighton





More information about the Python-list mailing list