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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c1fe4bc1dd51fc87 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: User-defined type attributes (replacing genericity) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <30f629fd-69d3-4d40-995f-9933f52b8dad@s37g2000prg.googlegroups.com> <965suhjl0bxt$.74se2ylyksin.dlg@40tude.net> <1205505100.6445.60.camel@K72> <821256cd-2d20-46dd-92d2-cdd21181dbb8@s8g2000prg.googlegroups.com> Date: Fri, 14 Mar 2008 19:58:18 +0100 Message-ID: <199nmfx3bkxkf$.1sllgktbwkbur.dlg@40tude.net> NNTP-Posting-Date: 14 Mar 2008 19:58:19 CET NNTP-Posting-Host: 2506cd68.newsspool1.arcor-online.net X-Trace: DXC=^O2D4VD7Cjg:i=48;n?Z:`ic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgb^5Z:A^WBc=n[6LHn;2LCVn[ On Fri, 14 Mar 2008 10:51:25 -0700 (PDT), Eric Hughes wrote: > On Fri, 14 Mar 2008 15:31:40 +0100, Georg Bauhaus wrote: >> Without generics, there is only one Is_Highest, as might be >> expected. > > On Mar 14, 8:48 am, "Dmitry A. Kazakov" > wrote: >> Why there have to be two? The whole idea of generics was to have *one* >> generic body. This is why it is called generic [programming]. > > Here's the nut of the problem. There is one generic body in the code > of the programming language. When you substitute type parameters into > that generic body, you get multiple different manifestations of that > original generic body, that is, multiple bodies, one for each type. > And that means multiple versions as translated into machine code. No, Ada is not like that. In fact much efforts, at least in Ada 83, was paid in order to allow sharing of generic bodies. AFAIK, Janus Ada shares them. > This is indeed the primary desideratum of generic programming. Having > said this, there's a standard technique of converting type operations > into virtual function calls. I feel like I need to say this--these > aren't the same thing. This allows the reduction of the manifestation > a generic body to a single canonical form. This has a single version > in machine code. It is optimization technique. You could instruct the compiler to inline a class-wide body. You could require to generate a separate instance for each used combination of argument types. Semantically the body is still same. > A realistic system for generic programming should support both modes > of code generation. This allows the developer to determine their own > answer to the code-size vs. performance trade-off. Ada has already > taken the stance, as evidenced by representation clauses, that it will > support both high and low levels of abstraction. If that were true it would be a premature optimization. Anyway semantically there is no any difference between generic and class-wide bodies. Both act on a class of types. To be honest, there are formal generic parameters beyond types: 1. Formal objects. These are not required and covered by plain functions. Normally they are used to work around language limitations, usually in types algebra, which is the weak point. 2. Formal packages. This looks like a useful thing, but child packages and better classes might make them superfluous. > Eliminating generics > would force everything into virtual function calls, choose code-size > over performance, and make that choice on behalf of every programmer. > If you go down the road of requiring all method calls to be virtual, Note that class-wide bodies do not dispatch. > of requiring that there be run-time manifestations of all meta- > language features, you get Java. Java has its place. So does Ada. > These aren't the same place. Similarly I could argue that Ada generics (at least as you an George describe them) is a preprocessor. There are many. Right, they are poorly designed, untyped etc. But who said that Java was designed properly? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de