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

Larry Hastings larry at hastings.org
Sun Apr 26 06:23:39 CEST 2009

Chris Rebert wrote:
> Except the ternary operator only allows for expressions, not
> statements; IIRC, GvR was somewhat reluctant about having any sort of
> ternary operator, so this further extension seems unlikely to me.

The suffix form of "if" can also be found in generator expressions and 
list/set/dict comprehensions.  What all these constructs have in common 
is that they're expressions, which means they can be buried in the 
middle of other expressions.  And being able to bury an "if" in there 
too is a boon to the programmer--one that the "if" *statement* could not 

But this is a subtle point, easily lost on non-language-nerds.  I work 
with an excellent programmer who nevertheless didn't grasp the 
distinction, even as I attempted to explain it to him.  So, for most 
Python programmers, the language feels like "an if statement looks like 
this, and btw you can have ifs in the middles and ends of lines too 
sometimes".  I hardly think the suffix form of "if" to "break" and 
"continue" would be the conceptual straw that broke the back of the 
language's cognitive load.

As for GvR, I gave up trying to predict his reactions a long time ago.  
Though I admit I'd be very surprised if my proposal, or indeed any 
proposal, won favor; PEP 315 is long enough in the tooth I fear we are 
doomed to never find a majority.  (A majority being defined here as 
either 2/3 majority of python-dev voters, or indeed the lone BDFL.)  
Witness PEP 3103, the switch statement; I think we'd all like to have 
one, if we could only figure out how to spell it.

And I personally would value a switch statement more than do/while,


More information about the Python-ideas mailing list