comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <jrcarter@acm.org>
Subject: Re: Return statements and their scope - guideline
Date: Wed, 14 Feb 2007 16:41:15 GMT
Date: 2007-02-14T16:41:15+00:00	[thread overview]
Message-ID: <LYGAh.1196164$084.827457@attbi_s22> (raw)
In-Reply-To: <eqvcsh$ql3$1@cernne03.cern.ch>

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



  reply	other threads:[~2007-02-14 16:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-14 16:20 Return statements and their scope - guideline Maciej Sobczak
2007-02-14 16:41 ` Jeffrey R. Carter [this message]
2007-02-14 17:31   ` Adam Beneschan
2007-02-15  7:33     ` Maciej Sobczak
2007-02-15  7:37   ` Maciej Sobczak
2007-02-14 16:46 ` Adam Beneschan
2007-02-14 20:06 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox