[Python-ideas] Updating PEP 315: do-while loops

spir denis.spir at free.fr
Sun Apr 26 20:04:37 CEST 2009


Le Mon, 27 Apr 2009 01:36:29 +0900,
"Stephen J. Turnbull" <stephen at xemacs.org> s'exprima ainsi:

I do not understand the resistance against the "footer" options, there must be something I cannot figure out. So my favored pattern in case a header option would win the game is:

until condition:
   <suite>

I think
* 'until' expresses far better an exit-condition than 'while' (even if this advantage is largely broken by the fact it is placed on top)
* in this case(*) we don't need any weird nicety like '...' (I say 'weird' because the sign itself has nothing to do with the meaning we want it to carry.)

(*) First because 'until' is new in python. Second because it carries a sense of 'end'.

> So as I'm reading down the page, it's natural for the structured
> concept (high level decision of what to do) to be above the detailed
> implementation (lower level decisions about how to do it).  Having the
> complete condition available at the top of a structure is something
> I've always wanted from do ... while or repeat ... until (but didn't
> know that until Raymond pointed it out<wink>), because it's not enough
> to know that this is a structure. 

Sure. While it certainly depends on individual (largely unconscious) strategies of programming and parsing. Anyway.

How important is this really in practice?
* Consider that to properly understand if..(else), if...elif...elif, try...except, for...(else) blocks, etc... we need to do the same kind of mental job. Who complains about it?
* Worse: Many of these blocks have _optional_ clauses. Even worse: you're not even warned about it by the header. This does not trouble me so much...
* Usually the loop fits in a page, so that your eyes can jump forward. (Otherwise there are other means, including folding and refactoring ;-)

This is not joking. I do not find

do:
   ...
   ...
   ...
until cond

more difficult to parse than for instance

if cond:
   ...
   ...
   ...
elif cond:
   ...
   ...
   ...
elif cond:
   ...
   ...
   ...

Anyway. 
Denis
------
la vita e estrany



More information about the Python-ideas mailing list