|
Posted by szr on March 21, 2008, 11:36 am
Please log in for more thread options Joost Diepenmaat wrote:
>> Correct me if I'm wrong, but are not last/next/redo with labels basic
>> `goto` statements that enact a last, next, or redo on the loop
>> associated with the label?
>
> Not exactly. Since you can only use them to go up the call stack
> another way to think of them is as special exceptions with built-in
> handlers.
Yeah but they seem to use the goto-label system in a way still (when
using loops with labels.. see two paragraphs down.)
> For real fun, see common lisp's condition/restart system.
Will do.
> In any case everything that alters the program flow can ultimately be
> seen as a (conditional) goto. Even such basic operators as && and if()
True. Though my point was a somewhat about the fact that they use the
same labels that goto uses for it's jump destination so next/last/redo +
label seemed like a goto with an additional instruction that acts on the
loop belonging to that label's context.
>> Does this constitute a necessary evil, or more rather, demonstrates
>> an instance where `goto` (in some form) has a place?
>
> It just demonstrates a useful pattern for program flow, which IMO is
> better handled by having explicit operators with predefined behaviour
> than by goto.
Agreed.
> The main problem with goto for me is that it's so unrestricted it
> *can*
> lead to code that's very hard to understand and bugs that are hard to
> analyze, not that it's inherently evil or anything like that.
True. I've just always seen it something that does have it's place like
anything else, and must be handled with much are when used (though I do
not really explicitly use goto in my programs, just never found the
need, to be perfecly honest :-)
> Perl has enough useful flow control operations and other features that
> it's rare to run into situations where goto() is the cleanest /
> clearest / obvious choice.
And this is probably /why/ I've never really needed to use goto in Perl
(though I also never needed to use it and c/c++ and the likes.)
--
szr
|