comp.lang.ada
 help / color / mirror / Atom feed
From: Eryndlia Mavourneen <eryndlia@gmail.com>
Subject: Re: Generics vs. O-O?
Date: Thu, 1 Aug 2013 12:52:42 -0700 (PDT)
Date: 2013-08-01T12:52:42-07:00	[thread overview]
Message-ID: <f5f74e31-52fd-465f-b16a-3b5beff97c69@googlegroups.com> (raw)
In-Reply-To: <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net>

On Thursday, August 1, 2013 2:24:57 PM UTC-5, Dmitry A. Kazakov wrote:
> On Thu, 1 Aug 2013 07:45:13 -0700 (PDT), Eryndlia Mavourneen wrote:
> 
> > I need to write a template package to be used by several different
> > mechanisms (units).  The question is, "What are the trade-offs between
> > using a generic package as the template and using a package-as-class
> > containing O-O code?"  I am aware that generics can take more time to
> > compile; however, I am more interested in run-time effects.
> 
> I don't really understand the question.
> > Can anyone provide a short summary?
> 
> 1. Both generics and OO (tagged types) represent polymorphism.
> 
> 2. Generics is so-called parametric or static polymorphism.
> 
> 3. Tagged types is dynamic polymorphism.
> 
> 4. Beyond "generic programming" generics are not restricted to only types.
> In Ada one can have generic objects, operations, anything that can be put
> into a generic unit.
> 
> 5. Considering run-time effects generics obviously have none because it is
> static polymorphism.
> 
> 6. Generic classes are implicit and have no objects. Tagged classes are
> explicit and may have class-wide object
> 
> 7. Formal generic types of Ada are weakly typed. Matching is by structure.
> User-defined generic types (ADTs) are not supported. User-defined
> operations on formal types are not supported. The language of formal
> generic parameters is somewhere between FORTRAN-IV and K&R C.
> 
> 8. Tagged types are fully integrated into Ada's type system. Still some
> classes of Ada types are not proper tagged classes, e,g, numbers, tasks
> etc.
> 
> 9. Generic units are basically non-testable. Substitutability issues are
> difficult to verify because of 7.
> 
> 10. For tagged types substitutability is a problem as well.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thank you, Dmitry.  This is pretty much my understanding.  I have run into problems several times with the "weakly typed" issue with generics.  It usually means adding additional formal parameters or making the parameter in question less general.

The run-time overhead would appear to be in favor of generics cpu-wise; however, the memory overhead for non-shared generic code could be substantial.  I believe you have some experience with this.

I think that I actually will use a combination of generic code and O-O, using generic parameters to bring in one or two external data types and using the O-O to introduce the subprograms as well as the type that maintains state.

-- Eryndlia (KK1T)

  reply	other threads:[~2013-08-01 19:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-01 14:45 Generics vs. O-O? Eryndlia Mavourneen
2013-08-01 19:24 ` Dmitry A. Kazakov
2013-08-01 19:52   ` Eryndlia Mavourneen [this message]
2013-08-01 20:14     ` sbelmont700
2013-08-01 23:35       ` Yannick Duchêne (Hibou57)
2013-08-01 20:10   ` optikos
2013-08-01 20:26     ` Dmitry A. Kazakov
2013-08-01 20:35     ` Jeffrey Carter
2013-08-01 21:22     ` Bill Findlay
2013-08-01 23:38     ` Yannick Duchêne (Hibou57)
2013-08-01 22:20   ` Georg Bauhaus
2013-08-02  8:11     ` Dmitry A. Kazakov
2013-08-02  9:50       ` Georg Bauhaus
2013-08-02 14:09         ` Dmitry A. Kazakov
2013-08-02 15:08           ` Shark8
2013-08-02 15:36             ` Alan Jump
2013-08-02 17:00               ` Jeffrey Carter
2013-08-02 17:51               ` Dmitry A. Kazakov
2013-08-02 18:06                 ` Alan Jump
2013-08-02 19:08                   ` Dmitry A. Kazakov
2013-08-02 16:15             ` Dmitry A. Kazakov
2013-08-03  0:04       ` Yannick Duchêne (Hibou57)
2013-08-03  7:35         ` Georg Bauhaus
2013-08-03  8:57           ` Dmitry A. Kazakov
replies disabled

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