Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> PL/SQL Tip of the Month

PL/SQL Tip of the Month

From: Cam White <info_at_revealnet.com>
Date: 1998/03/04
Message-ID: <01bd471a$d76b57e0$4973b1cd@Preveal2>#1/1

From the PL/SQL Pipeline - a free internet community for PL/SQL developers around the world. Check the pipeline for tips & hints, lively discussions, free white papers and utilities, monthly "puzzlers" and more. The PL/SQL Pipeline is hosted by best-selling author Steven Feuerstein and sponsored by RevealNet.
http://www.revealnet.com/pipeline.htm

March's Tip of the Month - One Way In, One Way Out

If you want to write code that is easy to debug, understand and maintain, then you should follow this rule:

One Way In, One Way Out

This means that for any procedure, function or loop, there should be only one way to initiate that program element, and one way to (successfully) terminate that program element.

Consider this FOR loop:

FOR monthnum IN 1 .. 12
LOOP
calc_monthly_sales (monthnum)
IF monthnum > 8
THEN
EXIT;
END IF;
END LOOP; While there is only one way to start the loop, the loop terminates in one of two ways: the loop index reaches 12 and stops, or the EXIT statement is executed. This is misleading code. I consider a FOR loop a promise: I will let this code iterate as specified and then continue. An EXIT inside the FOR loop means that my program can "bail out" under a variety of circumstances. In this simple example, the various paths are clear. On the other hand, if your program has 500 lines of gnarly code your ability to trace the execution path will diminish greatly.

So follow these simple rules:

Fully-functional trial software now available at http://www.revealnet.com Received on Wed Mar 04 1998 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US