comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: return statements in procedures
Date: 2000/06/05
Date: 2000-06-05T00:00:00+00:00	[thread overview]
Message-ID: <8hg6k7$t37$1@nnrp1.deja.com> (raw)
In-Reply-To: 393B2054.618F6E80@baesystems.com.au

In article <393B2054.618F6E80@baesystems.com.au>,
  Matthew Daniel <matthew.daniel@baesystems.com.au> 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.




  reply	other threads:[~2000-06-05  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-06-05  0:00 return statements in procedures Matthew Daniel
2000-06-05  0:00 ` Robert Dewar [this message]
2000-06-05  0:00 ` Geoff Bull
2000-06-06  0:00   ` Robert A Duff
2000-06-05  0:00 ` Marin D. Condic
2000-06-06  0:00   ` Geoff Bull
2000-06-06  0:00     ` Marin D. Condic
2000-06-05  0:00 ` Ted Dennison
2000-06-05  0:00 ` r_c_chapman
2000-06-05  0:00   ` Robert Dewar
replies disabled

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