PEP 315: Enhanced While Loop

rzed rzantow at ntelos.net
Sat May 3 20:34:16 EDT 2003


"W Isaac Carroll" <icarroll at pobox.com> wrote in message
news:mailman.1051933692.17571.python-list at python.org...
> PEP: 315
> Title: Enhanced While Loop
> Version: $Revision: 1.1 $
> Last-Modified: $Date: 2003/05/02 22:53:32 $
> Author: W Isaac Carroll <icarroll at pobox.com>
> Status: Draft
> Type: Standards Track
> Content-Type: text/plain
> Created: 25-Apr-2003
> Python-Version: 2.4
> Post-History:
>
>
[...]
>
>      This PEP proposes to solve these problems by adding an optional
>      clause to the while loop, which allows the setup code to be
>      expressed in a natural way:
>
>          do:
>              <setup code>
>          while <condition>:
>              <loop body>
>
>      This keeps the loop condition with the while keyword where it
>      belongs, and does not require code to be duplicated.
>
>

This does not strike me as "natural" in Python. By indenting the code
block as shown, a Python programmer would naturally see two blocks, the
second conditioned by a while statement. The normal logic of a while
would mark it as the loop beginning, not as somewhere in the middle of a
loop.

Even if the indentation were arranged differently, for a programmer
coming from the background of a language with a do ... while (or do ...
until) construct, the spec is not natural. The test would be expected at
the very end of the loop (or would at least be applied at the end of the
loop).

This seems to address a problem that doesn't really exist, and to try to
solve it in a forced manner, with rules that do not work as the rest of
the language does.

The main issue seems not to be the creation of a "do once, then test"
loop, but the elimination of duplicated setup code. That duplication can
happen, once in a great while, but is it really frequent enough, or
serious enough, to drive a syntactic upheaval? There are Pythonic ways
of dealing with the issue, and in the worst case, they include
duplicating the code. What's the big deal? It doesn't happen often and
the existing mechanisms can be used to handle the situation when it
does.

Python doesn't need much sugar to make it go down, and in this case,
it's more a case of syntactic garlic -- great for some, but not for
everyone, and for those who don't use it, it just stinks.

--
rzed








More information about the Python-list mailing list