PEP 315: Enhanced While Loop

Scott Chapman scott_list at mischko.com
Sat May 3 17:01:23 EDT 2003


On Friday 02 May 2003 21:23, Ben Allfree wrote:
> Can you provide an example snippit?
>
> And for that scenario, I would propose a simple "until" loop construct that
> is guaranteed to execute once before evaluation:
>
> # Old way
> MakeMoney()
> while Poor():
>    MakeMoney()
>
> # New way
> until not Poor():
>    MakeMoney()
>
> The above example assumes one must MakeMoney() before running the Poor()
> test ;)
>
> Python programmers would just have to understand that the "until" construct
> executes once before evaluation. Or maybe it could be named something more
> obvious. "AfterWhile" - heh - no pun intended.

I like the clean syntax of this suggestion but I see two problems with it:

1) It doesn't handle the same case that the PEP proposed syntax handles:

until not Poor():
   MakeMoney()
   SpendMoney()

SpendMoney() would have to check for not Poor() before spending.  This is a 
dependency that is totally unacceptable.

PEP syntax would work (if I understand it correctly):

do:
    MakeMoney()
while not Poor():
    SpendMoney()

2) Making anything that Python programmers would "just have to understand" is 
not Pythonesque and should be avoided.

The PEP proposed syntax is far too unclear as well, requiring that the Python 
programmer "just understand" that both MakeMoney and SpendMoney are executed 
each iteration through the loop.  

The syntax seems to say that SpendMoney is the only thing executed through 
each iteration.  

For instance, the question of which comes first, MakeMoney or SpendMoney, in 
the loop execution is not clear.

I would vote for no change to the language before adding this confusing syntax 
to it or the alternative proposal.  If a clean, straightforward syntax can be 
created, great.  These seem to me to violate the Zen of Python.

Cordially,
Scott






More information about the Python-list mailing list