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: 103376,ad62d6b425bebfec X-Google-Attributes: gid103376,public From: mg@asp.camb.inmet.com (Mitch Gart) Subject: Re: "use" clauses and Ada 95 OOP Date: 1996/07/23 Message-ID: #1/1 X-Deja-AN: 169660714 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: asp.camb.inmet.com references: organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-07-23T00:00:00+00:00 List-Id: Stephen Schmid (schmid@alta.ide.com) wrote: : Mitch Gart wrote: : > : > > To me the C++/Java syntax : > > : > > x.func : > > : > > seems clearer than the Ada syntax in this case because what is being : > > called is the function that is associated with X at runtime, rather than : > > the function that comes from a given package. : > : The above call in C++ does not mean that the function associated with : the class X will get called at runtime. If x is a reference to a class, : and func is a virtual function, then x.func will 'dispatch' (to use an Ada : term) to the function corresponding to whatever class x happens to refer : to at runtime, which could be x or any subclass of x, so the situation is : similar to that which occurs in Ada. Yes the calls dispatch, in Ada 95 and C++/Java. But my point is that a naive Ada 95 reader might think that the call pkg1.func(x) calls the code that is in the body of pkg1. The syntax in fact implies that strongly. To know it's not true a reader has to look at the spec of pkg1 and figure out that x is a tagged type and func is a primitive operation on a variable or anonymous access type, in order to know that the call is dispatching. In Ada 83 if a reader sees the call pkg1.func he can look at the body of pkg1 to see what statements will be executed. In Ada 95 he must also look at the spec of pkg1, to find the type declaration of X, to know whether the call is dispatching. : > > In Ada 95 OOP we can have the situation where a call : > > : > > pkg1.func(x) : > > : > > dispatches at runtime to : > > : > > pkg2.func(x) : > > : > > It seems to me that this notation is misleading because a reader might : > > think that the function in pkg1 will be executed. : > > : I don't think this is misleading, and I would argue in favor of not using : the use clause. With the use clause, the reader has no clue as to : which function is being called without checking the context clauses, and : there is greater opportunity for error. You are giving the reader _less_ : information, which cannot be helpful. Including the package name gives : the reader a starting point to determine what functions may be called at : runtime. In a language with run-time dispatching, that is the most that : you can do. The choice is between giving the reader less information, versus giving him misleading information. - Mitch