Thoughts on PEP315

Stephen Horne $$$$$$$$$$$$$$$$$ at $$$$$$$$$$$$$$$$$$$$.co.uk
Tue Sep 23 07:08:06 CEST 2003


On Tue, 23 Sep 2003 04:33:27 GMT, "M-a-S" <NO-MAIL at hotmail.com> wrote:

>If it was up to me, I would propose
>
>until <condition>:
>    <statements>
>
>as an equivalent to:
>
><statements>
>while not <condition>:
>    <statements>

If your reason for using 'until' is simply to test for 'while not',
then this doesn't make sense.

I assume you intend the 'until' to be a postcondition rather than a
precondition. Writing this at the start of the loop suggests that it
is a precondition (the word 'until' does not automatically imply a
postcondition). I want the condition to be written at the location
where it is tested - for a postcondition this means the end. Which
means you still need something to mark the start of the loop, and you
end up with...

  loop:
    <statements>
  until <condition> :

Nothing wrong with that in particular of course, but it's not so
different to the 'break if' I proposed. No different at all, in fact,
except using a different name and...

>loop:
>   <statements>
>
>for the enless loop, instead of ugly 'while True'.

I have no problem with that in principle, except that adding new
keywords can be a problem in itself. 'break if' avoids having a new
'until' keyword, and does not require a 'loop' keyword to replace the
'while'. Having a 'loop' keyword could be a good thing or not - it's a
different issue.

Of course, it might be acceptable to make the condition in the 'while'
optional, so you could write...

  while :
    <statements>
  break if <condition> :


But then there would be the whole explicit-is-better-than-implicit
thing - I seriously doubt it would be accepted.

Alternatively...

  for ever :
    <statements>
  break if <condition> :

The 'ever' wouldn't need to be a keyword - the lack of the 'in'
clearly differentiates it from existing 'for' loops so Python could
just validate the identifier name if it finds a colon where it expects
the 'in'.

You're suggestion of 'loop' certainly looks better than either of
these, but my suspicion is that looking good wouldn't outweigh the
need to avoid adding too many new keywords ("loop" may be used a lot
as an identifier name).


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk




More information about the Python-list mailing list