From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: on OO differnces between Ada95 and C++
Date: 1996/02/20
Date: 1996-02-20T00:00:00+00:00 [thread overview]
Message-ID: <4gdidj$10f5@watnews1.watson.ibm.com> (raw)
In-Reply-To: 4gbq7q$g08@qualcomm.com
In article <4gbq7q$g08@qualcomm.com>, nabbasi@qualcomm.com (Nasser Abbasi)
observes that in C and C++ one specifies an interface in a .h (or .H)
file and imports the interface with a #include directive, while in Ada
one specifies an interface with a program-unit declaration (typically a
package declaration) and imports it with a with clause. In C and C++
importing is transitive--if B #includes A and C #includes B, then C has
effectively #included--while in Ada it is not--if B has a with clause for
A and C has a with clause for B, then A is not visible in C unless C has
its own explicit with clause for A.
I prefer the Ada model for two reasons:
1. The Ada model provides a more precise description of which library
units are visible where. A library unit is visible only in
compilation units naming it in a with clause. Some Ada programmers
use subunits to make this information even more precise. For
example, if the only place in a large package body where Ada.Text_IO
is used is in one particular procedure body, that procedure body may
be broken off into a subunit and the with clause for Ada.Text_IO
placed on the subunit rather than the package body, to make clear to
readers that Ada.Text_IO is only used in that one procedure.
2. In a compilation unit U that refers to an imported entity X, the Ada
model makes it easier to find the unit exporting X. It must be a
unit named in a with clause on U, on the corresponding declaration if
U is a body, or a parent unit.
When the programmers deem it appropriate, it is possible for one package
to reexport entities declared in another package using renaming, subtype,
and number declarations:
package A is
type T is ...;
procedure P(X: in out T);
Y: constant T := ...;
...
end A;
with A;
package B is
subtype T is A.T;
procedure P(X: in out T) renames A.P;
Y: constant T := A.C;
...
end B;
However, reexport is not forced on the programmer as in the case of a .h
file that #includes another .h file. In the example above, if a
compilation unit C has a with clause for B and refers to T, P, or Y, the
reader for C can refer to the declaration of B to find declarations for
T, P, and Y.
In OOP, it is often desirable for entities declared along with a parent
type P to be reexported along with any type D derived from P. This can
be achieved automatically by deriving from P in a child of the package in
which D is declared:
package Parent is
type Auxiliary_Type is ...;
type P is tagged ...;
procedure Op (X: in out P; Y: in Auxiliary_Type);
...
end Parent;
package Parent.Child is
type D is new P with ...;
procedure Op (X: in out D; Y: in Auxiliary_Type);
...
end Parent.Child;
A compilation unit that mentions Parent.Child in a with clause is, in
effect, really importing a version of Parent with Parent.Child nested
inside of it, so the declaration of Auxiliary_Type comes along.
--
Norman H. Cohen ncohen@watson.ibm.com
next prev parent reply other threads:[~1996-02-20 0:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-02-20 0:00 on OO differnces between Ada95 and C++ Nasser Abbasi
1996-02-20 0:00 ` Robert I. Eachus
1996-02-20 0:00 ` Jerome Desquilbet
1996-02-21 0:00 ` Robert Dewar
1996-02-22 0:00 ` Jerome Desquilbet
1996-02-24 0:00 ` Robert Dewar
1996-02-22 0:00 ` Pete Becker
1996-02-23 0:00 ` Jerome Desquilbet
1996-02-26 0:00 ` Darren C Davenport
1996-02-26 0:00 ` Pete Becker
1996-02-27 0:00 ` Nigel Perry
1996-02-20 0:00 ` Norman H. Cohen [this message]
1996-02-21 0:00 ` Mark A Biggar
1996-02-22 0:00 ` Norman H. Cohen
1996-02-27 0:00 ` Adam Morris
1996-02-21 0:00 ` John English
1996-02-22 0:00 ` Gene Ouye
1996-02-26 0:00 ` John English
1996-02-22 0:00 ` Nasser Abbasi
1996-02-26 0:00 ` John English
1996-02-27 0:00 ` Dale Stanbrough
1996-02-21 0:00 ` Jon S Anthony
1996-02-21 0:00 ` Darren C Davenport
-- strict thread matches above, loose matches on Subject: below --
1996-02-21 0:00 Christian Jaensch, FRG
1996-02-26 0:00 Simon Johnston
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox