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

Chris Rebert pyideas at rebertia.com
Sun Apr 26 05:59:16 CEST 2009


On Sat, Apr 25, 2009 at 8:39 PM, Larry Hastings <larry at hastings.org> wrote:
> Chris Rebert wrote:
>>
>> I don't see why the if-as-suffix is needed when we already have a
>> one-liner for such situations (e.g.):
>>
>> if i != '1': break
>>
>> It's much more uniform and only one character longer.
>>
>
> I certainly see your point.  Let me take it a step further: the "do: ...
> while <condition>" construct isn't needed, given that it's already
> expressible with "while True: ... if not <condition>: break".
>
> It's true, "break if <condition>" and "continue if <condition>" are
> redundant constructs.  But this debate is over refining our syntactic
> sugar--charting what is arguably a redundant construct.  Therefore proposing
> redundant constructs for the sake of clarity is on the table.  I think
> "break if <condition>" and "continue if <condition>" enhance readability;
> they make the control flow pop out at you more than "if <condition>: break"
> and "if <condition>: continue" do.  "break if" and "continue if" have the
> advantage of following established Python syntactic precedent.

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.
Allowing general if-suffixes on things also seems a bit Perlish, imho.
I find the current state of syntactic simplicity quite appealing.

Regarding visibility, how is the last word of the last line in a loop
body, further set off by the if's colon, not visible enough? I
personally haven't ever had problems spotting the breaks in
loop-and-a-half code.

On another note, I actually do like the bare-while-as-while-True idea
quite a bit. +1 on that.

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-ideas mailing list