Status of PEP's?

Alan Daniels daniels at mindspring.com
Thu Mar 7 00:19:48 EST 2002
Michael Chermside <mcherm at destiny.com> wrote in message
news:<mailman.1015421793.13369.python-list at python.org>...

The objection you quoted was from me originally, so I feel compelled
to respond to it here.

[snippety doo dah, snippety ay...]
> 1) I think that  "for i in range(len(items)):"  is awkward, annoying,
>    and detracts from Python. There should be a better way.

I agree. The nicest counter-proposal I've seen so far is...
    for i in indices(items):
        print i

> *PLEASE* disregard the whole "set theory" argument. I don't think
> that anyone defending PEP 276 is suggesting it as the motivation...

I know, I know... I *was* on a rant, true, but I never used the "set
theory" argument as a straw man. In fact, I was disappointed that this
was the only provided justifcation for seeing an integer as a sequence.
I was hoping for something more substantial, and less tongue-in-cheek.

There's still some MAJOR problems I see with PEP 276:

1) Right now, we have complete orthogonality between "for" and "if".
"for i in seq:" will be called for each value where "if i in seq:" is
true. Adding "for i in 5" destroys this.

2) If you can iterate over integers, a newbie will rightfully wonder
why it is that you cannot iterate over floats. "for i in 5" may be up
in the air, but I doubt that anyone would agree that "for i in 5.0"
could ever be meaningful.

I brought this up before but no one responded to it. If anyone has any
feedback on this I'd appreciate it.

3) PEP 276 still doesn't handle the case where you need "steps", such
as something like:
    for i from 1 to 10 step 2:
        print i
Or something along that line. I'm using Basic-style syntax here as an
example, not a recommendation. :-)

4) I actually *like* that you have to use xrange(len(seq)) to iterate
over the indices of a sequence (strange, I know). In my own code, I
try to refer to indices as little as possible. When I see this...
    for index in xrange(len(seq)):
Instead of this...
    for item in seq:
...I take that as a subtle hint that I need to rethink that part of
the code. But that's mostly a matter of individual style.

Anyway, done ranting (again!). Have a good one.



More information about the Python-list mailing list