comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin D. Condic" <mcondic-nospam@quadruscorp.com>
Subject: Re: return statements in procedures
Date: 2000/06/05
Date: 2000-06-05T14:08:08+00:00	[thread overview]
Message-ID: <393BB2E4.937BA4DA@quadruscorp.com> (raw)
In-Reply-To: 393B2054.618F6E80@baesystems.com.au

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
======================================================================




  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 ` Marin D. Condic [this message]
2000-06-06  0:00   ` Geoff Bull
2000-06-06  0:00     ` Marin D. Condic
2000-06-05  0:00 ` Geoff Bull
2000-06-06  0:00   ` Robert A Duff
2000-06-05  0:00 ` Robert Dewar
2000-06-05  0:00 ` r_c_chapman
2000-06-05  0:00   ` Robert Dewar
2000-06-05  0:00 ` Ted Dennison
replies disabled

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