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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,3f73d873d16dcda7 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns13feed!worldnet.att.net!attbi_s22.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Return statements and their scope - guideline References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1171471275 12.201.97.213 (Wed, 14 Feb 2007 16:41:15 GMT) NNTP-Posting-Date: Wed, 14 Feb 2007 16:41:15 GMT Organization: AT&T ASP.att.net Date: Wed, 14 Feb 2007 16:41:15 GMT Xref: g2news2.google.com comp.lang.ada:9324 Date: 2007-02-14T16:41:15+00:00 List-Id: Maciej Sobczak wrote: > > I have found a coding guideline that allows return statements only in > the outermost scope in the subprogram - which is supposed to avoid > obscuring the control flow. > > What is outermost scope in this context? > > function F return Integer is > begin > if Some_Condition then > return 0; -- (1) > end if; > -- ... > declare > X : Integer; > begin > -- ... > return X; -- (2) > end; > -- ... > return 7; -- (3) > end F; > > Is (1) above in the outermost scope? No. This is the rule in SPARK: You have to write if Some_Condition then Result := 0; else ... Result := ...; end if; return Result; This makes the analysis easier. However, I've always felt if Some_Condition then return 0; end if; is easier to read; if you're interested in the case where Some_Condition holds, then you don't have to read any further. I wonder how such coding standards will deal with the extended return statement of Ada 0X. -- Jeff Carter "I blow my nose on you." Monty Python & the Holy Grail 03