You know, I've seen a lot of people get really steamed that there was a
RETURN in the middle of a well structured subroutine.  Mostly because these
people SCREWED UP when they put something at the bottom of the subroutine
without checking, or worse TESTING the product before shoving it blindly
into production.

I see nothing wrong with a RETURN - especially in a validation subroutine.
Now.....an update subroutine is perhaps a bit different.  If that needs to
be broken up, I usually do it at the CALLING level, i.e.:

BEGIN CASE
  CASE LEVEL1
    GOSUB LEVEL1.UPDATES
  CASE LEVEL2
    GOSUB LEVEL2.UPDATES
  CASE REPRINT
    GOSUB BUMP.REPRINT.COUNTER
END CASE

Here's something I thought about while looking at the possibility of not
putting in a RETURN while at the same time keeping the code structured
without a bunch of indented tabs:

B00.PROCESS:
  BAD.HAPPENED = 1
  LOOP
    READ REC1 FROM file1,id1
      ELSE EXIT
    END
    READ REC2 FROM file2,id2
      ELSE EXIT
    END
    IF some.condition
      THEN EXIT
    END
    BAD.HAPPENED = 0
    EXIT
  REPEAT
  IF NOT(BAD.HAPPENED) THEN
    some more statements
    that actually do the work with REC1 & REC2
  END
RETURN

This does make it apparent that the subroutine is not being abandoned, while
making a unique use of the LOOP/REPEAT/EXIT construct, in that it is not
really a loop, but a method used for 'bouncing out'.  It begins by assuming
BAD.HAPPENED and will only negate this if it reaches the bottom of the
decision stack.

I've never used this before, and doubt that I will, but it was an
intellectual exercise aimed at 'staying structured' with a minimum of
IF/THEN's.  Personally, I just use the RETURN....no sense being 'analyst'
about it......  ;)

Allen

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Womack, Adrian
Sent: Tuesday, September 27, 2005 18:06
To: [email protected]
Subject: RE: [U2] Good Programming Practice Question.........


We also use "xnn.meaningful.name" type labels. One advantage is that our
editor can recognise a label and putting the cursor on a line that
includes a GOSUB and pressing one function key will move the cursor
directly to the correct paragraph.

One thing I've never agreed with (except in COBOL) is "every internal
subroutine should only have on exit point" - why?

What is wrong with...

B00.PROCESS:

        READ REC1 FROM file1,id1
           ELSE RETURN

        READ REC2 FROM file2,id2
           ELSE RETURN

        IF some.condition
           THEN RETURN

        some more statements
        that actually do the work with REC1 & REC2

        RETURN


The early RETURNs are just getting out of the routine on abnormal
conditions, the alternative would be to nest the code - but code nested
more than a couple of tabs deep is *much* harder to read.


AdrianW


DISCLAIMER:
Disclaimer.  This e-mail is private and confidential. If you are not the
intended recipient, please advise us by return e-mail immediately, and
delete the e-mail and any attachments without using or disclosing the
contents in any way. The views expressed in this e-mail are those of the
author, and do not represent those of this company unless this is clearly
indicated. You should scan this e-mail and any attachments for viruses. This
company accepts no liability for any direct or indirect damage or loss
resulting from the use of any attachments to this e-mail.
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/
-------
u2-users mailing list
[email protected]
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to