comp.lang.ada
 help / color / mirror / Atom feed
From: Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU>
Subject: Re: on OO differnces between Ada95 and C++
Date: 1996/02/27
Date: 1996-02-27T00:00:00+00:00	[thread overview]
Message-ID: <4guqvm$4cn@goanna.cs.rmit.EDU.AU> (raw)
In-Reply-To: DnDuA4.8GC@bton.ac.uk

John English, je@bton.ac.uk writes:
": If what you say was the case, then types defined in package "A"
: will be seen by clients to a package "B" where "B" has with'ed A. But
: it is not so. Clients of "B" must also 'with' "A" to see types
defined
: in "A" even though "B: has allready  with'ed "A".

If you're right this would be a real pain.  Clients of a package would
have
to know (recursively) what other packages the spec(s) reference; if the
spec for X "withs" a package Y so it can use type Y.T as a procedure
parameter then you wouldn't be able to use X without Y (i.e. "with X"
on its own would be useless; you'd have to have "with X, Y" and
probably
other things as well if Y has any "with" clauses in its specification.

This is such a horrible concept that I'm inclined to believe GNAT, but
if anyone who can understand all the subleties of the visibility rules
can give us all a definitive explanation in words of sufficiently few
syllables that Bears of Very Little Brain like me can understand, I for
one would be profoundly grateful."

Au Contraire, it's a great concept. It is SO nice to be able to see,
from the top of a listing, just what the relationship b/w the unit 
you are looking at to the rest of the system is.

I *hate* transtive 'with'ing relationships! When you read the code
of C/C++, you may have one #include at the top, but your code
references
all sorts of types/functions etc. Where do they come from? What range
of packages do I have to look at before I can find the declarations?
Should I do a broad search, or a depth first search on the #include
files
when looking for the declarations?
In Ada, with it's 'flat' view of 'with'ings (compared to C's deep
#include
model) you can easily see the level of coupling of a
package/compilation
unit.

A simple explanation is perhaps...

	"with"ing never extends beyond the units you have explicity "with"ed.
	If you need something that they have "with"ed, then you have to 
	with it as well. "With"ing is only ever one unit deep.
	
A simple example
	----------------------------------
	package a is
		type alpha is...
		
		function X return alpha;
	end a;
	
	----------------------------------
	with a;
	package b is
		type beta is
		
		procedure Y(item:       alpha);
		procedure Z(item:in out beta);
	end b;
	
	----------------------------------
	-- if you use resources from A,		-- If you don't use resources from
	-- then you have to "with" A.		-- A, then you can ignore it.
	with A;
	with B;								with B;
		
	procedure main is					procedure main is
		stuff	:A.alpha	:= A.X;			stuff	:B.beta;
	begin								begin
		B.Y(stuff);							B.Z(stuff);
	end;								end;
	
Important to note that if procedure main isn't going to declare any
alpha values, or call B.Y, then it doesn't need to with A at all.

The fact that B has "with"ed A can be viewed as a compositional
legacy from the construction of B. It has little to do with how
procedure main is constructed.

If "main" want's to use resources from A, then it explicity has to
declare it's intent for all the world to see.

The use clause only means you don't have to use dot notation (e.g.
B.Y) when accessing resources from the package.

I suspect that if you examine some real code that you will not
find too great a list of "with"ed units (esp. with well designed
code). Even if it were, I wouldn't be too concerned, as it aids
the reader of the code.


Dale




  reply	other threads:[~1996-02-27  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 ` Norman H. Cohen
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-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 ` Robert I. Eachus
1996-02-21  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 [this message]
1996-02-22  0:00   ` Gene Ouye
1996-02-26  0:00     ` John English
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