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 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.7.7 with SMTP id b7mr5728830qab.5.1375387839874; Thu, 01 Aug 2013 13:10:39 -0700 (PDT) X-Received: by 10.49.5.106 with SMTP id r10mr138793qer.11.1375387839826; Thu, 01 Aug 2013 13:10:39 -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!fx3no514154qab.0!news-out.google.com!he10ni48qab.0!nntp.google.com!fx3no514147qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 1 Aug 2013 13:10:39 -0700 (PDT) In-Reply-To: <1wugpqyea6s39$.e2e8eshup5wn$.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=64.183.207.38; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 64.183.207.38 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: optikos@verizon.net Injection-Date: Thu, 01 Aug 2013 20:10:39 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3383 Xref: news.eternal-september.org comp.lang.ada:16642 Date: 2013-08-01T13:10:39-07:00 List-Id: On Thursday, August 1, 2013 2:24:57 PM UTC-5, Dmitry A. Kazakov wrote: > [... snip ...] > 5. Considering run-time effects generics obviously have none because it i= s > static polymorphism. > [... snip ...] Not so fast. Your statement on your #5 is true for C++ templates, but not = true for Ada generics. The difference is that instantiations by different = combinations of template-parameters of a C++ template result in a combinato= rial explosion of the quantity of instances of that template's machine code= & static data. Conversely, Ada utilizes a single instance of machine code & static data fo= r an Ada generic, regardless of the type parameters passed at compile-time.= This single instance of machine-code accommodates different type paramete= rs by either branching (around different per-type-parameter treatment) or t= able look-up (of the size & structure of entities). No such branching or t= able-lookup is present in the corresponding combinatorial explosion of C++ = template instantiation. This conflation by branching or table look-up in A= da is precisely why the combinatorial explosion does not occur in Ada gener= ics, as it does in C++ templates. Hence, Ada's branching and table-lookups will in fact incur some execution-= time overhead when compared to analogous C++ templates and when compared to= nongeneric equivalent functionality. Conversely, when looking at code blo= at, Ada's generics will incur some executable-size space overhead when comp= ared to nongeneric equivalent functionality, but both the Ada generic and t= he nongeneric equivalent functionality will result in drastically smaller e= xecutables than a (na=EFvely-designed) C++ template that is instantiated wi= th a vast quantity of combinations of parameters to that C++ template. Hen= ce, in C++, the best-practice is to manually design a C++ template whose no= ntemplated guts accomplishes the conflation that the Ada compiler performs = for an Ada generic. In C++ this often means that a type-safe C++ template = thinly ricochets off to a nontemplate/nongeneric functionality that utilize= s void* & corresponding sizeof to defeat all type-safety of objects or scal= ars.