From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,9ac62ca34a465706 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,9ac62ca34a465706 X-Google-Attributes: gid103376,public From: Dale Stanbrough Subject: Re: on OO differnces between Ada95 and C++ Date: 1996/02/27 Message-ID: <4guqvm$4cn@goanna.cs.rmit.EDU.AU>#1/1 X-Deja-AN: 141330741 distribution: world references: <4gbq7q$g08@qualcomm.com> <4gt3ag$76m@druid.borland.com> content-type: text/plain; charset=ISO-8859-1 x-xxmessage-id: organization: Royal Melbourne Institute of Technology mime-version: 1.0 newsgroups: comp.lang.ada,comp.lang.c++ Date: 1996-02-27T00:00:00+00:00 List-Id: 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