I’ll start by commenting on the “one entry, one exit” rule. It arose in
the bad old days of assembler programming.
After all, how many OO languages do you know where it is possible to
have multiple entries to a routine? When I was taught VAX Macro one of
the “techniques” taught was to have a register bitmask that also
evaluated to a useful instruction. That way you could use the same
address for a JSR (Jump SubRoutine) and for a CALL. Really clever
developers also managed to jump into the middle of a subroutine, do
something useful and then jump elsewhere before reaching the return
statement. Needless to say, drawing a structure programming flowchart
for this code was really, really difficult. Maintaining said code was
even worse:-)
Modern OO languages by comparison, only have 1 way of entering a
routine, so early exit does not have anywhere near the problems that
assembler programmers were able to cause. Indeed, it is common to have
multiple exits. For example, Martin Fowler’s book Refactoring talks
about the use of Guard clauses which explicitly encourages multiple
returns (exits).
http://www.refactoring.com/catalog/
replaceNestedConditionalWithGuardClauses.html
So my take on this is that while some of the old structured programming
rules are still useful, we need to reevaluate all in the light of
modern programming paradigms.
“Reinterpreting your experiences is very important in times of change.
The reason is that as things change, we need to see if what we learned
in the past is still applicable and relevant.” - Chapter 5, Questioning
XP … Pete McBreen
Pete
···
On Saturday, December 7, 2002, at 10:24 PM, Ted wrote:
- The “routine” has more than one exit. This violates the “one
entry, one exit” rule of structured programming.
Comments?
Pete McBreen, McBreen.Consulting , Cochrane, AB
Author, “Software Craftsmanship The New Imperative”
Winner of 2002 SD Productivity Award
Author: “Questioning Extreme Programming”
Addison-Wesley (c) 2003