From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9e90e30a519a635b X-Google-Attributes: gid103376,public From: "Marin D. Condic" Subject: Re: return statements in procedures Date: 2000/06/05 Message-ID: <393BB2E4.937BA4DA@quadruscorp.com>#1/1 X-Deja-AN: 631287977 Content-Transfer-Encoding: 7bit References: <393B2054.618F6E80@baesystems.com.au> Organization: Quadrus Corporation X-Sender: "Marin D. Condic" (Unverified) X-Server-Date: 5 Jun 2000 14:08:08 GMT Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-06-05T14:08:08+00:00 List-Id: Matthew Daniel wrote: > procedure Blah (....) is > > begin > > if .... then > return; > end if; > .. > end Blah; While you might want to question the design of a procedure that had some large number of "return" statements scattered throughout it, I don't see what makes one or more "return" statements inherently evil. I think some folks fear it because of an almost slavish devotion to the "No Goto's" rule. (BTW, I've been programming in Ada for over 15 years and never once used a goto for anything other than illustration purposes. Not that I fear them - just never had much use for one. ;-) That said, I have used the "return" statement in procedures on a number of occasions where I may be doing some kind of immediate validity check up front and want to quit rather than go through the rest of the code, or when you get into checking lots of conditions (nested "if" situations) and you've determined that the branch you're on means its time to quit. Judicious use of the "return" statement can make it easier to understand the code. Avoiding it at all cost can lead to some butt-ugly convolutions that are harder to understand. My vote would be to go ahead and do it, but always ask if it is making things better or if it is an indication that the design is flawed. (Are you asking the procedure to do too much? Is there a simpler way to implement the requirements?) MDC -- ====================================================================== Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/ Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m Visit my web site at: http://www.mcondic.com/ "Some people think programming Windows is like nailing jello to the ceiling... easy with the right kind of nails." -- Ivor Horton - Beginning Visual C++ 6 ======================================================================