I'm very old school and learned my structured programming in PASCAL.  The
cardinal rule is that you enter every block of code from the top, and you
exit it from the bottom.

No one ever got hurt doing this.

I can only remember one case in recent history where I actually used
mulitple exit points.  The routine was supposed to decide if a client was
eligible for something.  I set the answer to "No" at the top the routine,
and "Yes" at the bottom.  There were all kinds of tests in between.
Failure of any test executed a "RETURN" statement, before it reached the
line of code that set the answer to "Yes".  I did it that way because I
thought it was actually clearer than embedded IF statements.

We needed to make a modification a few years later to suspend eligibility
for all customers for a time.  That could have been achieved by simply
putting a RETURN near the top of the routine.  Curiously, the programmer
assigned that task seemed simply unable to comprehend how the routine
worked, and made a mess of it.  He would have had no problem dealing with a
set of embedded IF's.

I had to look up the "CONTINUE" statement.  In 25 years I've never used it,
and don't even remember seeing it used.  Now I know what it does I think it
should be banned.

My approach to situtations like this, where the control structure around a
block gets so split up that it's hard to see at a glance what it's doing,
is to put the functional block into an internal subroutine.  I'd much
rather see:

BEGIN CASE
CASE OPTION 1
  GOSUB OPTION.1.FUNCTIONAL.CODE
CASE OPTION 2
  GOSUB OPTION.2.FUNCTIONAL.CODE
CASE OPTION 3
  GOSUB OPTION.3.FUNCTIONAL.CODE
END CASE

Than see a single case statement that ran across hundreds of lines of code.
I've also done stuff like this:

GOSUB OPERATION.1
IF (NOT(ERROR)) THEN
  GOSUB OPERATION.2
  IF (NOT(ERROR)) THEN
    GOSUB OPERATION.3
    IF (NOT(ERROR)) THEN
      GOSUB OPEARTION.4
    END
  END
END

Which I think nicely splits out the control structure and makes it clear at
a glance how the program works.


Dave Barrett,
Lawyers' Professional Indemnity Company
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to