cross
|
|
response 15 of 45:
|
Jan 26 20:11 UTC 2007 |
Note something about this solution: basically, we're using functionality of
the language that effectively implements a goto. But, clearly someone
recognized the need for such a thing and added it to the language, thus
obviating the need to use goto to break out of a nested loop structure.
Actually, we have several things of this nature in modern programming. For
instance, exceptions are nothing more than glorified goto's with some
additional state information associated with them. So the concept is
useful, and what you've seen in the 40 years since Djikstra wrote ``Goto
Statement Consider Harmful'' in Communications of the ACM is a selective
identification of the instances where goto really *added* something to
programming, and an extraction of those paradigms into codified programming
constructs. In other words, the language designers took what was useful and
recast it as a first class language component. Multi-level loop control
statements (e.g., as implemented in Perl's labelled loops) and exceptions
are the two important examples.
So, in a language where we have those things, is goto still useful? I'm not
sure. But, from the pro-goto side of the house, let's quote Ken Thompson
from the Plan 9 fortune file:
"If you want to go somewhere, goto is the best way to get there. K Thompson"
My own sense is that goto is never strictly necessary, and hardly ever
useful, particularly in modern programming languages where we have
exceptions and multi-level loop control constructs (when I *have* used goto
in real programs, it was almost always to break out of nested loops).
By the way: there's still another algorithm for the matrix problem that
is both elegant and efficient that avoids goto and doesn't require the
loop control constructs I used (in fact, it can be implemented entirely
in ISO standard Pascal and doesn't require a BREAK or CYCLE). Can anyone
find it?
I'm most curious, once it's discovered (I know at least one person reading
this knows the solution, since he made it up, and Nate probably does too,
since he read the M-Net thread, so it *will* be discovered) to compare it
to a solution that uses the `modern' language functions. Which is more
obvious? Which is more efficient? What other metrics would one judge
something like this by?
|