PEP-315 ("do" loop)

John Roth newsgroups at jhrothjr.com
Tue Feb 17 07:15:34 EST 2004


"Wayne Folta" <wfolta at netmail.to> wrote in message
news:mailman.55.1076984559.31398.python-list at python.org...
Two observations about PEP-315:

1. It's clever, addresses a definite "wart", and is syntactically similar to
try/except. But it's syntax seems like an acquired taste to me.

2. It is a very general construct, which might be what is called for. But I
wonder if most of the time it would be used to accomplish something like:

while 1:
    line = sys.stdin.readline()
    if line == "\n":
        break

In a neater way? How about, instead, creating an "until" loop:

until line == "\n":
    line = sys.stdin.readline()

Would be defined to work exactly like a while loop except the test is not
evaluated the first time through the loop. Wouldn't this be akin to checking
at the end of the loop, while maintaining a more while-ish syntax?

Is this at all useful or is something of the order of PEP-315 the way to go?

[response]

1. I've reindented your examples - they don't indent properly under some
browser.

2. Please use plain text - the reason your message isn't quoted properly is
that you used something else, and my news client breaks the formatting.

Now to the substantive responses.

1. The proposed syntax breaks Python's indentation scheme in a manner that
try-except, for-else, while-else, and if-elif-else do not.

2. What I find more serious is that there are a huge number of ways to go in
"improving" the basic while loop, none of which seem to be a natural
stopping point. Python's philosophy seems to be to find the "sweet spot"
where you gain the most leverage with the minimum amount of mechanism.
Neither PEP-315 nor any of the "improvements" I've seen do that.

John Roth





More information about the Python-list mailing list