Michael A. Covington said:
Much closer to home, here's what Steve McConnell (of "Code Complete")
says:
http://www.stevemcconnell.com/ccgoto.htm
Basically an extended demonstration that 'goto' has its legitimate uses.
In particular, he shows you some algorithms where "Use no gotos" conflicts
directly with the principle "Only express each idea once". Duplicate code
is bad because your two expressions of the same idea may not be identical,
especially if, later on, you have to maintain the code; you may not
succeed in keeping them in sync.
Being a fan of McConnell, I made a careful read of the page you pointed me
to. It is interesting that the path that he chose to illustrate his "no go
to" debate from was one that illustrates how to REWRITE code from "including
goto" to "excluding goto." I have a problem with this characterization.
The cognitive exercise places into the mind an understanding of the
algorithm from the viewpoint of a procedure written with goto in mind, and
then attempts to show that the algorithm is less readable or potentially
more prone to problems if you rewrite it. This shows only that if you
present an idea, in one form, and ask your reader to go through a mental
exercise to understand it, that it may be hard for that same reader to
immediately follow the exercise with one in which s/he has to relearn the
algorithm from another point of view. I'm not completely convinced that the
mental process that the reader goes through in this example is a valid
process for comparison, because it is a "code-only" process and does not
factor in design time considerations.
In other words, what Steve did NOT do is illustrate how valid OO thinking
would have led away from this situation in the first place. The author of
the code is much more likely not to have written code filled with "goto"
statements and this triggering this rewrite and the ensuing comparison,
because a person who described applications in terms of their patterns would
not have lept to the conclusion that an implementation that uses goto makes
much sense.
As a coding leader, it is my responsibility to encourage this kind of
thinking, because the benefits it reaps across the project are immense. If
a programmer in using 'goto', even in a rational and constrained way, I
would be led to wonder if he was thinking about the problem in terms of
patterns, since there are no OO patterns that use the goto.
In fact, the specific example that you cite is nearly perfect for
demonstrating the effective use of the strategy pattern, where parts of an
algorithm are seperated from, and replacable by, other parts. This, in
effect, creates a system whereby control structures within an algorithm can
be seperated from calculation logic and expressed independently.
It is also interesting to note that this article, like the rest, makes the
comparison between structured programming with the 'goto' and structured
programming without the 'goto.' No article makes the comparison with OOP in
the mix. Perhaps this is because no more recent study on the debate,
including in the OO world, has found anything new to say. Or, perhaps, no
one cares as much any more.
I'm afraid that we will not agree on this point. However, I appreciate the
discussion.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--