Like I said: if the goto approach works for you, more power to you. Me, I find:
loop {
@stuff = grep { $_->valid } @stuff;
TEST: last unless @stuff;
$_->do_something( ++$i ) for @stuff;
}
to be at least as straightforward as:
goto INVARIANT;
while ( @stuff ) {
$_->do_something( ++$i ) for @stuff;
INVARIANT:
@stuff = grep { $_->valid } @stuff;
}
It strikes me as being more concise; and the use of the (superfluous)
label makes the position and significance of the "last unless..." line
stand out.
I'm not telling you that you're wrong; TIMTOWTDI. I'm telling you
that it's a matter of taste.
On Fri, Dec 19, 2008 at 5:52 AM, Aristotle Pagaltzis <[email protected]> wrote:
> * Jon Lang <[email protected]> [2008-12-19 03:50]:
>> Personally, it doesn't strike me as being as straightforward
>> as putting a "last unless" clause into the middle of an
>> otherwise-infinite loop
>
> You have to keep more state in your head to read
>
> while(1) {
> # ...
> last if $foo;
> }
>
> than to read
>
> while($foo) {
> # ...
> }
>
> The goto in the code I gave happens just once and doesn't modify
> the loop semantics. Basically, any one point in the code I gave
> can be read in isolation, and is "locally complete" (I don't know
> how to say this better), whereas in the infinite loop the overall
> effect of certain points is depenent on other points.
>
> In Schwern's terms, goto'ing into the middle of a terminating
> loop is more skimmable than last'ing out of the middle of an
> infinite loop.
>
> Regards,
> --
> Aristotle Pagaltzis // <http://plasmasturm.org/>
>
--
Jonathan "Dataweaver" Lang