PEP 284, Integer for-loops

Graham Breed usenet at microtonal.co.uk
Sat Mar 9 05:51:00 EST 2002


Tim Legant wrote:

> Out of curiosity I ran a couple of quick greps over the TMDA source.
> TMDA doesn't really fall into either of your "alternative" categories;
> it's small, but definitely not throwaway and it's an application, not
> a core library.  It's a mail processor to eliminate SPAM.  However,
> it's pure Python; there's no integration with C or Java.

How small is small?  I have a script at 
<http://www.microtonal.co.uk/temper.py> with around 1490 lines (including 
comments and blank lines) and 35 uses of range, some probably evil, most 
for for loops.  Two warty examples

  for n in range(1,n+1,2):

and

      for element in range(firstIndex, maxBasis+1):

where the +1 is used for inclusive boundaries.  7 straight 
range(len(..))s.

> The results were that I found 52 or 53 'for' loops (scanned the
> results of the grep by eye, since the word 'for' appears in comments
> as well) and exactly no uses of [x]range at all.

I have 107 instances of the word "for", which may include comments.

> So either Jason and I are significantly better than you and your team
> at expressing ourselves naturally in Python <wink> or it's the need to
> interface with Java that's forcing you to use integer indices all the
> time.  I'm betting big money on the latter.

Well, I've stuck my head above the parapet.  Have a look at the code, and 
see if I'm expressing myself badly.  It doesn't integrate with C, Java or 
COM but does do a lot of work with integers.  That's not something Python 
excels at, but it's such a good language generally that it's still worth 
using outside its niche.

I still don't see a need for language changes, but I can see that people 
doing heavier number theory than me would.


                   Graham




More information about the Python-list mailing list