while true: !!!

Bjorn Pettersen pbjorn at uswest.net
Mon Dec 18 09:38:52 EST 2000


Steve Lamb wrote:

> [snip]

> IMHO trying to cater to the novice at the expense of maintainability for
> the experts is not something to strive for in a language.  Introducing a
> design where a statement is contradictory is also not something to strive for.
> That is why we have "while 1:" because it is obvious to all who see it what it
> is beyond, say, the first day or so with the language and it doesn't have the
> problems "for ever" and "while true" impose.

Isn't catering to the novice what cp4e is/was all about <wink>? You're correct of course, that "while
1:" is pretty trivial to understand, and so is "x = x + 1", however neither is telling the reader
exactly what you're doing. The most common reason for using "while 1:" (at least in newspostings ;-) is
because saying what you _really_ mean <0.5 wink>:

   for line in f.readlines():
      ...

has the potential of crashing your machine with an out-of-memory error if you don't know the sizes of
files you're operating on. Using the fileinput module, or any of the other possible wrappers that have
been posted is just too slow. So, the status quo is that because the straight-forward way of doing it is
too slow, we're all using an optimized idiom that while easy to understand if coming from a CS
background, doesn't model what you're doing (at least not until you've programmed enough Python that
reading a file seems like an  endless loop <wink>).

-- bjorn




More information about the Python-list mailing list