why no "do : until"?

Bjorn Pettersen pbjorn at uswest.net
Thu Jan 4 12:45:33 EST 2001


Hi Alex,

Sometimes I think you can type faster than I can read, so you'll have to excuse
the excessive snippage :-)

Alex Martelli wrote:

> "Bjorn Pettersen" <pbjorn at uswest.net> wrote in message
> news:3A53F4B1.6227D241 at uswest.net...
>     [snip]
> > If what you want to do can't be expressed directly in the language, and
> > the only reason people don't want to change it is because they're used to
> > the status quo, I feel justified in calling it a holy cow ;-)
>
> [snip]
> I *WOULD* mind, *A LOT*, if, rather than regularizing syntax for the
> general form of loop, Python were to add other special-cases with
> their own syntax variations.  *SIMPLICITY*!  *ONE* general loop form

I guess this is where our opinions differ. I'm of the school of "make the
general case easy, but make the common case trivial". This means I'm strongly
in favor of adding special cases for often used looping constructs. I'm _not_
in favor of adding special cases for every conceivable looping construct
however. E.g. I'm not in favor of adding a do/while loop.

In the project I'm currently working on (C++, ~33 Kloc) there are 346 while
loops, and only 24 do/while loops. Of the while loops, 12 are "while(1)" (there
are also three for(;;)), 95 contain an assignment ("while (line =
fp.readline())"), and the rest contain "regular" tests. I'm therefore likely to
argue against adding do/while, and special syntax for "while 1" (i.e. loop: or
while:), but for adding special syntax for assignments in the test part of a
while loop (on the principle that if they're used that frequently in a language
that has them, they must be somewhat useful).

The project also contains 884 for loops, and though I didn't check, I would
assume most of them are of the form "for (i=0;i<j;i++)", which means I would
probably argue for special syntax for the Pythonic "for i in
range(len(sequence))"... (perhaps "for i in 1..10" or perhaps a special form of
list comprehensions "for i in [1..10 by 2]" <wink>)

At least we both agree that the print>> syntax is a wart, and perhaps also that
the special casing of print>>None is counterintuitive ;-)

but-it-was-Guido's-baby-as-is-Python'ly y'rs
-- bjorn





More information about the Python-list mailing list