while true: !!!

Alex Martelli aleaxit at yahoo.com
Tue Dec 12 11:22:33 EST 2000


"Steve" <smnordby at yahoo.com> wrote in message
news:3A36368C.26AADDDE at yahoo.com...
> I dislike infinite while loops and use:
>
> for line in file.readlines()
>     ...do stuff...
>
> No need for a break since it will automagically when it runs out of
> lines.

Surely best, *IF* you're 100% sure that all the files you
ever read will always fit comfortably in memory.

If you must provide for reading huge files, this will just
not work.

Would you rather have a program with a construct you 'dislike',
but that will work; or a program you like a lot, that just does
not work?  I.e., are you a pragmatist, or an aesthete?

Python is first and foremost a highly pragmatical language --
although it seems to attract more than its share of aesthetes.

Python's beauty, like that of a sturdily-built brick outhouse,
is not the beauty of frills and decorations, and it's not the
stark minimalist beauty of less-is-more, either: it is, rather,
the beauty of simplicity, solidity, and fitness-for-purpose.

Firmitas, Utilitas, Venustas -- in *THIS* order, as Vitruvius
had it, NOT "comodità, perpetuità, bellezza" as Palladio did --
FAR too much software puts intended 'convenience' first, to the
detriment of solidity, but Python, like Unix, is in the GREAT
architectural tradition of *solidity FIRST*.  But that's another,
secondary flamethread (which has been running even since Leon
Battista Alberti swapped the firs two words in the list...) --
the Classical theorists and the Renaissance ones may differ on
the order of the first two priorities, but they do agree in
the placement of the third one... last among the three.

If 'venustas'/'bellezza'/'delight' is not the third of the
triad for you, but higher-up in the pecking-order, then you
may not be getting as much out of Python as it has potential
to give (it may still be a lot, and quite possibly still more
than other languages, but perhaps you might be happier with
languages which afford aesthetics-for-aesthetics'-sake a
higher importance than 'does it run' and 'does it run WELL').


"Infinite" loops are hardly ever appropriate -- loops normally
do terminate (although it may be appropriate to model, with
an "infinite" loop, one that is intended to run until the
machine itself is turned off, for example).  However, loops
that are meant to "cycle until told othewise" (are terminated
by an exception, a signal, or a condition best computed inside
the body of the loop itself) are extremely common.  If your
aesthetic sense interferes with their effective and idiomatic
usage, then it is most likely leading you astray.


Alex






More information about the Python-list mailing list