PEP 284, Integer for-loops

Steve Lamb grey at despair.dmiyu.org
Wed Mar 6 19:08:44 EST 2002


On Wed, 06 Mar 2002 15:35:06 -0800, David Eppstein <eppstein at ics.uci.edu>
wrote:
> I diagree that the current method has both, or either.  I don't know 
> about you, but I find "for x in range(n-1,-1,-1)" to be a difficult to 
> read and difficult to understand way of obfuscating a simple loop over 
> the numbers 0 to n-1 in reverse order.  I think "for n > x >= 0" would 
> be much simpler.

    As stated in the PEP, perceived problem.  for foo ? bar ? baz is less
clear.  Difference is, range[foo,bar,baz] is what is there and, for anyone who
takes the time to learn the language instead of looking for problems, finds
that it is quite clear.  Start, end, step.  Furthermore the "for x in foo" is
generic enough that one can also prepare the list in any manner they choose.

    Overloading for adds unneeded complexity to address nothing more than a
perception problem for those reading the code wanting something their way
because they are too lazy to learn the ways the language already allows the
same thing to be done.

    IE, this is the same thing we get every time someone stumbles onto Python
and gets thier knickers in a twist because while (1): violates what their
college professor stated.  NO INFINITE LOOPS!  Nevermind that the if statement
right after the while does provide the same break.  No, we get endless wars
that we should have a do:while loop and a do:until loop and lord knows what
other loop constructs to fit very specific cases which are handled just fine
with a general construct.

    We have two looping constructs.  While and for.  Both give you ways to
address the problem.  We do not need an overloaded construct just to appease
your sense of asthetics.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
    To email: Don't despair!   |  -- Lenny Nero, Strange Days
-------------------------------+---------------------------------------------



More information about the Python-list mailing list