while (a=b()) ...
Aahz Maruch
aahz at netcom.com
Sun May 16 10:25:38 EDT 1999
In article <373DBCDA.99AD27D3 at home.com>, Jim Meier <fatjim at home.com> wrote:
>Aahz Maruch wrote:
>> In article <373DAF53.4287D726 at home.com>, Jim Meier <fatjim at home.com> wrote:
>>>> Aahz Maruch <aahz at netcom.com> wrote:
>>>>>
>>>>> for line in f.readline()
>>>>> frobulate(line)
>>>
>>>As was told to me previously, this *is* excellent, readable and usable..
>>>But while it does solve the big, big "while 1"-is-not-an-infinite-loop
>>>ugliness, the use of break is still involved instead of other, harder-edged
>>>controls. I have no problem with this, I just felt like nit-picking to
>>>recover my manliness. <whoops-blew-my-cover-style grin>
>>
>> How is break involved?
>
>As in, when you want to be done with processing before being finished
>iterating:
>
>for tick_tick_tick in series_of_hardships:
> work_work(tick_tick_tick)
> work_work(tick_tick_tick)
> if revolution_is_ripe:
> break
As Knuth says, "Premature optimization is the root of all evil." I'm
not interested in trying to create a structure that completely removes
the possibility of using break. The essential problem that we want to
fix is the desire for the idiom
while line = foo.readline() :
frobulate(line)
With the ability to easily use "for" over a lazy-eval sequence, we take
care of that issue and a host of similar ones. In your example above,
revolution_is_ripe is an exceptional condition and should be handled in
an exceptional manner; one could even argue that break is the wrong
statement and that raise should be used. But this is programming
philosophy removed from what I would call "normal use".
(I should note, in fact, that your complaint about break applies just as
much to the desire for the while idiom.)
--
--- Aahz (@netcom.com)
Hugs and backrubs -- I break Rule 6 <*> http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het
'It's odd, and a little unsettling, to reflect upon the fact that English is
the only major language in which "I" is capitalized; in many other languages
"You" is capitalized and the "i" is lower case.' -- Sydney J. Harris
More information about the Python-list
mailing list