comp.lang.ada
 help / color / mirror / Atom feed
From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: Is 'out' different from 'in out' (Was: Uninitialized "out" parameters)
Date: 1996/07/25
Date: 1996-07-25T00:00:00+00:00	[thread overview]
Message-ID: <Dv30DH.K4w.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: gauthier-2307961037570001@164.81.60.62


Michel Gauthier (gauthier@unilim.fr) wrote:
: ...
: Possible useful style rule : avoid 'out' parameters, since they
: are error-prone, and prefer 'in out'.

I don't agree.  If the incoming value of a parameter is irrelevant to 
the algorithm of the routine, it should specify the parameter as 
an "out" parameter.  This conveys more information to the user.  

Furthermore, if the parameter is of an elementary type,
you can end up with more error possibilities with "in out", because if the 
caller forgets to initialize the actual parameter, you might or might not 
get a constraint error on the way in, depending on what "stack junk" 
is sitting in the variable when the call is made.

With an "out" parameter, you only need to remember to initialize
in one place, namely in the beginning of the routine with the OUT
parameter.  No constraint checks are performed on the way in for
an elementary OUT parameter, eliminating the requirement for each
caller to initialize the actual parameter to some irrelevant value.

Note that if you believe it is rare to need to read an OUT parameter anyway, 
then there is no difference in "safety" between the Ada 83 and Ada 95
OUT parameters.  If you believe it is common to need to read an OUT
parameter, then in Ada 83, you had to introduce an extra variable,
and then copy the value from that into the OUT parameter, creating
*two* possibilities for error: forgetting to initialize this extra
variable, and forgetting to copy the extra variable into the OUT
parameter on all exit paths.  The Ada 95 approach seems like a
wash or a win in both cases.

: Michel Gauthier / Laboratoire d'informatique
: 123 avenue Albert Thomas / F-87060 Limoges
: telephone +33 () 55457335 [or ~ 7232]
: fax +33 ()  55457315  [or ~7201]

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




  parent reply	other threads:[~1996-07-25  0:00 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-18  0:00 Uninitialized "out" parameters Paul Whittington
1996-07-18  0:00 ` Adam Beneschan
1996-07-18  0:00   ` Robert Dewar
1996-07-19  0:00   ` Samuel Tardieu
1996-07-19  0:00     ` John Herro
1996-07-19  0:00       ` Tucker Taft
1996-07-23  0:00         ` Peter Hermann
1996-07-23  0:00           ` Robert A Duff
1996-07-19  0:00   ` Dale Stanbrough
1996-07-19  0:00     ` Adam Beneschan
1996-07-19  0:00     ` James A. Squire
1996-07-19  0:00       ` Adam Beneschan
1996-07-20  0:00       ` Michael Feldman
1996-07-21  0:00         ` Fergus Henderson
1996-07-21  0:00           ` Michael Feldman
1996-07-21  0:00             ` Robert Dewar
1996-07-22  0:00             ` Fergus Henderson
1996-07-23  0:00               ` Michael Feldman
1996-07-23  0:00                 ` Robert Dewar
1996-07-25  0:00                   ` Fergus Henderson
1996-07-24  0:00                 ` Fergus Henderson
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-19  0:00   ` Pascal Obry
1996-07-19  0:00     ` Peter Hermann
1996-07-18  0:00 ` Robert Dewar
1996-07-19  0:00   ` Peter Amey
1996-07-20  0:00   ` Fergus Henderson
1996-07-20  0:00     ` Robert Dewar
1996-07-21  0:00       ` Fergus Henderson
1996-07-21  0:00         ` Robert Dewar
1996-07-23  0:00           ` Richard A. O'Keefe
1996-07-23  0:00             ` Robert Dewar
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-25  0:00               ` Richard A. O'Keefe
1996-07-25  0:00                 ` Robert A Duff
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Richard A. O'Keefe
1996-07-24  0:00                 ` Robert A Duff
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-25  0:00                     ` Robert A Duff
1996-07-24  0:00                 ` Theodore E. Dennison
1996-07-25  0:00                 ` Frank Manning
1996-07-25  0:00                   ` Richard A. O'Keefe
1996-07-26  0:00                     ` Frank Manning
1996-07-23  0:00           ` Fergus Henderson
1996-07-23  0:00             ` Robert A Duff
1996-07-24  0:00               ` Fergus Henderson
1996-07-24  0:00               ` Fergus Henderson
1996-07-19  0:00 ` Michel Gauthier
1996-07-21  0:00   ` Robert A Duff
1996-07-19  0:00 ` Peter Amey
1996-07-21  0:00 ` Robert A Duff
1996-07-22  0:00 ` Is 'out' different from 'in out' (Was: Uninitialized "out" parameters) Michel Gauthier
1996-07-22  0:00   ` Tucker Taft
1996-07-22  0:00   ` Robert A Duff
1996-07-22  0:00     ` Robert Dewar
1996-07-23  0:00 ` Michel Gauthier
1996-07-23  0:00   ` Robert Dewar
1996-07-24  0:00   ` Pascal Obry
1996-07-25  0:00   ` Tucker Taft [this message]
1996-07-23  0:00 ` Uninitialized "out" parameters John Herro
1996-07-23  0:00   ` Robert Dewar
1996-07-24  0:00     ` Peter Hermann
1996-07-23  0:00   ` Robert A Duff
1996-07-24  0:00     ` Uninitialized variables, Java example Arra Avakian
1996-07-25  0:00       ` Richard A. O'Keefe
1996-07-25  0:00         ` Robert A Duff
1996-07-25  0:00       ` Robert A Duff
1996-07-26  0:00   ` Uninitialized "out" parameters Stephen J Bevan
1996-07-26  0:00     ` Robert A Duff
1996-07-24  0:00 ` Uninitialized variables, Java example Felaco
replies disabled

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