comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Inheritance versus Generics
Date: 1997/04/25
Date: 1997-04-25T00:00:00+00:00	[thread overview]
Message-ID: <E972A4.C0r@world.std.com> (raw)
In-Reply-To: 33601924.774@flash.net


In article <33601924.774@flash.net>, Craig Smith  <cdsmith0@flash.net> wrote:
>Generics were a very power feature of Ada-83.  With the OO features
>introduced into Ada-95 (in particuliar, the tagged record and ability to
>inherit), are Generics obsolute?

No, generics are not obsolete.  Bertrand Meyer explains why quite
clearly in his OO book.  He talks a lot about Eiffel, but his arguments
on this point apply to Ada as well.

*Some* uses of Ada 83 generics are better done with Ada 95 tagged types,
but certainly not all.  In fact, a mixture of the two features often
makes sense.  E.g., consider data structure generic package, like
"Generic_Lists", where the element type is a generic formal parameter.
You might want to have homogeneous lists of some specific type
(list-of-integer).  You might also want to have heterogeneous lists, by
passing in Some_Type'Class.  The same generic works for both.

If you use tagged types to make your lists, instead of generics, then
you end up losing type checking -- you *can't* constrain the type of
list elements.  (Java has this problem, as does Smalltalk.)  You also
end up having to derive from some central List_Item type, so if you have
an existing type T, you have to go back and modify if it you want it in
lists.  (Assuming the links are in the list items, which is one way you
might want to do it.)  (Smalltalk doesn't have this problem.  But then
it doesn't try to do much type checking.)

>...  I would guess since several features
>were added to generics (like generic formal package parameters), the
>answer is no.  Does anyone have any thoughts on this?

And generic formal derived types.

- Bob




  parent reply	other threads:[~1997-04-25  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-24  0:00 Inheritance versus Generics Craig Smith
1997-04-25  0:00 ` Robert Dewar
1997-04-25  0:00   ` Michael F Brenner
1997-04-25  0:00     ` Robert Dewar
1997-04-27  0:00       ` Nick Roberts
1997-04-29  0:00         ` Michael F Brenner
1997-05-02  0:00           ` John G. Volan
1997-05-02  0:00           ` Nick Roberts
1997-05-03  0:00             ` Robert Dewar
1997-04-29  0:00       ` Mats Weber
1997-05-01  0:00         ` Robert Dewar
1997-04-26  0:00   ` Michael Feldman
1997-04-25  0:00 ` Tucker Taft
1997-04-25  0:00 ` Robert A Duff [this message]
1997-04-25  0:00 ` Lionel Draghi
1997-04-25  0:00 ` Mats Weber
1997-04-27  0:00   ` Matthew Heaney
1997-04-27  0:00     ` Robert Dewar
1997-04-28  0:00       ` Bertrand Meyer
1997-05-03  0:00         ` Jon S Anthony
1997-05-04  0:00           ` Robert Dewar
1997-05-03  0:00         ` Robert A Duff
1997-05-03  0:00           ` Robert Dewar
1997-04-29  0:00     ` bertrand
1997-04-29  0:00       ` Robert Dewar
1997-04-28  0:00 ` Martin Lorentzon
  -- strict thread matches above, loose matches on Subject: below --
1997-04-27  0:00 tmoran
1997-05-03  0:00 tmoran
replies disabled

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