comp.lang.ada
 help / color / mirror / Atom feed
From: mg@asp.camb.inmet.com (Mitch Gart)
Subject: Re: "use" clauses and Ada 95 OOP
Date: 1996/07/23
Date: 1996-07-23T00:00:00+00:00	[thread overview]
Message-ID: <Duzwxx.8E1.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: SCHMID.96Jul22104727@alta.ide.com


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




  parent reply	other threads:[~1996-07-23  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-17  0:00 "use" clauses and Ada 95 OOP Mitch Gart
1996-07-19  0:00 ` Jon S Anthony
1996-07-19  0:00 ` James A. Squire
1996-07-22  0:00   ` Stephen Schmid
1996-07-23  0:00     ` JamesS1889
1996-07-23  0:00     ` Mitch Gart [this message]
1996-07-23  0:00       ` Robert Dewar
1996-07-25  0:00         ` JamesS1889
1996-07-26  0:00           ` Robert A Duff
1996-07-23  0:00       ` Robert A Duff
1996-07-23  0:00       ` Kevin J. Weise
1996-07-23  0:00       ` Kevin J. Weise
1996-07-23  0:00         ` JamesS1889
1996-07-23  0:00     ` JamesS1889
1996-07-23  0:00     ` Laurent Guerby
1996-07-23  0:00       ` Robert A Duff
1996-07-24  0:00     ` Jon S Anthony
1996-07-24  0:00     ` Jon S Anthony
1996-07-19  0:00 ` Robert I. Eachus
1996-07-23  0:00   ` Robert I. Eachus
1996-07-25  0:00     ` JamesS1889
1996-07-23  0:00   ` JamesS1889
1996-07-23  0:00     ` Robert Dewar
1996-07-24  0:00     ` Robert I. Eachus
1996-07-24  0:00   ` Jon S Anthony
1996-07-20  0:00 ` James A. Squire
1996-07-21  0:00   ` Robert A Duff
1996-07-22  0:00 ` Jon S Anthony
1996-07-23  0:00 ` Jon S Anthony
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox