From: smithd@software.org (Doug Smith)
Subject: Re: Reference vs. copy semantics in passing parameters
Date: 18 Feb 91 18:41:45 GMT [thread overview]
Message-ID: <1991Feb18.184145.1911@software.org> (raw)
In-Reply-To: 2635@enea.se
In article <2635@enea.se> sommar@enea.se (Erland Sommarskog) writes:
> Also sprach Micheal Feldman (mfeldman@seas.gwu.edu):
> >Jim Showalter (jls@yoda.Rational.COM) writes:
> >>In C++, you can declare not only the pointer constant but the pointed
> >>to construct constant as well. This allows passing by reference in a
> >>read-only manner, which is NOT possible in Ada at present.
> >
> >Well now I'm curious. Given that only scalars and small structures are
> >usually passed by copy, why would you want to guarantee reference
> >passing for read-only parameters in such a kludgy way? Ada provides you
> >with everything you need:
>
> Don't get confused by terminology. Forget about passing mechanisms.
> Remember data abstraction.
>
More specifically, notice how an ADT can be specified to control the
ambiguity of parameter modes for pointers to complex data structures.
Although a particular implementation of linked list might always
initialize a header record, then never need to change it during
Prepends, Appends, etc., IN OUT can enforce the intent of the
operations. For example:
package Linked_Integer_Operations is
type Lists is limited private;
procedure Append (List : in out Lists;
Element : in Integer);
private
... Declare Lists as an initialized record whose value
doesn't have to change during the Append operation.
end;
Now the application engineer cannot accidently change a list that he
did not originally intend to change:
procedure Reorder_List (New_List : in out Lists;
Old_List : in Lists) is
begin
Append (Old_List, 0); -- will not compile !!!
end;
-- RM 6.4.1(3): actual must be a variable name or a conversion
-- RM 6.2(3): assignment to an IN parameter not allowed
No matter how arrogant I become about my own programming skills, this
kind of compile time checking has saved me many headaches!
next prev parent reply other threads:[~1991-02-18 18:41 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-02-11 15:06 ADA Compiling Query Gordon Russell
1991-02-12 19:01 ` Michael Feldman
1991-02-13 21:16 ` Jeff Bartlett
1991-02-14 16:45 ` Michael Feldman
1991-02-15 23:09 ` Jim Showalter
1991-02-17 0:19 ` Reference vs. copy semantics in passing parameters Michael Feldman
1991-02-17 18:54 ` Erland Sommarskog
1991-02-18 18:41 ` Doug Smith [this message]
1991-02-18 0:36 ` Jim Showalter
1991-02-18 1:42 ` Michael Feldman
1991-02-18 18:49 ` Arthur Evans
1991-02-19 2:05 ` Michael Feldman
1991-02-18 13:10 ` madmats
1991-02-19 19:00 ` Robert I. Eachus
1991-05-16 13:51 ` Alex Blakemore
1991-05-17 8:19 ` Matthias Ulrich Neeracher
1991-05-17 13:44 ` Markku Sakkinen
1991-05-28 5:28 ` Kenneth Almquist
1991-02-18 14:33 ` ADA Compiling Query stt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox