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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.64.202 with SMTP id f10mr5675021qai.2.1375386762483; Thu, 01 Aug 2013 12:52:42 -0700 (PDT) X-Received: by 10.49.24.177 with SMTP id v17mr133651qef.23.1375386762351; Thu, 01 Aug 2013 12:52:42 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder02.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!fx3no512524qab.0!news-out.google.com!he10ni48qab.0!nntp.google.com!fx3no512515qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 1 Aug 2013 12:52:42 -0700 (PDT) In-Reply-To: <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=129.59.203.108; posting-account=7Oy7OQoAAABhVYFOo553Cn1-AaU-bSfl NNTP-Posting-Host: 129.59.203.108 References: <6238c325-79c5-4537-ba55-2800110dc6df@googlegroups.com> <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Generics vs. O-O? From: Eryndlia Mavourneen Injection-Date: Thu, 01 Aug 2013 19:52:42 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3747 Xref: news.eternal-september.org comp.lang.ada:16641 Date: 2013-08-01T12:52:42-07:00 List-Id: 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)