comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Gibson <dgibson@cis.ohio-state.edu>
Subject: Re: Cumbersome Polymorphism
Date: 1997/01/28
Date: 1997-01-28T00:00:00+00:00	[thread overview]
Message-ID: <32EE2269.41C67EA6@cis.ohio-state.edu> (raw)
In-Reply-To: 32ECF2A3.6371@watson.ibm.com


> > However, it seems that in order to make a very simple use of
> > polymorphism, I have been obliged to introduce access types.
> 
> Yes, this is generally the case in Ada 95.

Right.  Access types do seem necessary for inheritance-style inclusion 
polymorphism required for dynamic binding in Ada.  However, access types 
are not necessary to achieve generics-based parametric polymorhphism.  While
generics without exposed use of access types only provide static binding
in Ada, this approach can have a number of advantages (assuming a good
generics-savy compiler).  

> > And now by bringing in access types I have imported the problems
> > that go with them.
> 
> You are using an access type in a very restricted and disciplined way.
> I'm not sure what you mean by "the problems that go with them", but the
> fact that undisciplined use of access types may cause problems is
> irrelevant.  Your solution does not involve any such problems.

Well, even if you have a strong discipline that avoids aliasing-related
reasoning problems which access types can introduce, I personally think
that the code is just more difficult to read and understand when access
types are used as much as dynamic dispatching in Ada seems to require.

> > However, as is well known, the problem with requiring the user
> > of a type to perform explicit deallocation is that he may forget
> > to do so somewhere in the code, resulting in a memory leak.
> 
> I don't understand the problem.  The need for the deallocation operation
> is encapsulated in the package.  The writer of the package ensures that
> there is never more than one object allocated.  The user of the type
> never has to know about it.  Indeed, the declaration of your access type
> ought to be moved out of the package declaration and into the package
> body.

Yep.  That's an important part of a strong discipline for software
component engineering.

Dave
--
dgibson@cis.ohio-state.edu




  parent reply	other threads:[~1997-01-28  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-23  0:00 Cumbersome Polymorphism Richard Irvine
     [not found] ` <5c9put$48t@hetre.wanadoo.fr>
1997-01-25  0:00   ` Robert A Duff
1997-01-25  0:00     ` James O'Connor
1997-01-26  0:00       ` Robert Dewar
1997-01-26  0:00       ` Brian Rogoff
1997-01-25  0:00   ` James O'Connor
1997-01-27  0:00   ` Jon S Anthony
1997-01-29  0:00     ` Robert Dewar
1997-01-27  0:00 ` Norman H. Cohen
1997-01-28  0:00   ` Jon S Anthony
1997-01-28  0:00   ` Dave Gibson [this message]
1997-01-28  0:00   ` Richard Irvine
replies disabled

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