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, MSGID_RANDY 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: Robert Dewar Subject: Re: return statements in procedures Date: 2000/06/05 Message-ID: <8hg6k7$t37$1@nnrp1.deja.com>#1/1 X-Deja-AN: 631247210 References: <393B2054.618F6E80@baesystems.com.au> X-Http-Proxy: 1.0 x57.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Jun 05 12:32:07 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-06-05T00:00:00+00:00 List-Id: In article <393B2054.618F6E80@baesystems.com.au>, Matthew Daniel wrote: > Hi, > > we are having a "discussion" at work at the moment about return > statements in procedures. > > There is one who believes it is acceptable for certain > circumstances and the rest of us do not believe it should > occur. The "one" is to be commended. Any time you decide that a feature in Ada should never ever be used, you are almost certainly making a mistake. If that was really the case, the feature would not be in the language to start with. In the case of return, it definitely can be advantageous to use this construct and can often make code far easier to read. For example if deep in a list of nested if's I see if ..... then Record_No_Good; Result := No_Good; return; end if; I know immediately that processing is complete at the point of the return. I do not have to unwind through the nested if's to see if any more processing remains to be done. Another common case is right at the start of the procedure if .... then return; end if; immediately indicating cases where the procedure does nothing and getting rid of them from the mind of the reader. That's usually better than enclosing the entire rest of the procedure one level down in an else. The rule is simple. Use return when it makes things clearer to read. > > just seeing what every one else thinks. > > Matt > > eg > > procedure Blah (....) is > > begin > > if .... then > return; > end if; > .. > end Blah; > Sent via Deja.com http://www.deja.com/ Before you buy.