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,2a34b7ad6c6a0774 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!87.79.20.105.MISMATCH!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Efficiency of code generated by Ada compilers Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Sat, 7 Aug 2010 09:53:10 +0200 Message-ID: NNTP-Posting-Date: 07 Aug 2010 09:53:10 CEST NNTP-Posting-Host: e70b5ea5.newsspool3.arcor-online.net X-Trace: DXC=FEMKWIW4AFR=>bdbdS?M0YMcF=Q^Z^V3X4Fo<]lROoRQ8kF\af_k3TGlA1R]jU X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:12923 Date: 2010-08-07T09:53:10+02:00 List-Id: On Fri, 6 Aug 2010 13:21:48 -0700 (PDT), Elias Salom�o Helou Neto wrote: > I would like to know how does code generated by Ada compilers compare > to those generated by C++. The short answer is yes, of course. The long answer is that such comparisons are quite difficult to perform accurately. > I use C++ for numerical software > implementation, but I am trying to find alternatives. Ada is especially good for this, because it has an elaborated system of numeric types with specified accuracy and precision (and behavior), which C++ lacks. > One thing, > however, I cannot trade for convenience is efficiency. Will Ada > compiled code possibly be as efficient as that generated by C++ > compilers? Certainly yes. Potentially Ada code can be more efficient, because in Ada your program usually tells the compiler more than in C++. This information can be used in optimization. > Also, I do need to have something similar to C++ "templated > metaprogramming" techniques. Ada has generics which are roughly same as templates. Unlikely to C+ generics are contracted and not automatically instantiated. > In particular, C++0x will introduce > variadic templates, which will allow us to write templates that will > generate efficient, type-safe, variable-argument functions. Is there > anything like that in Ada? No. > If any of the above questions is to be negatively answered, I ask: why > does Ada even exist? Do you mean variadic templates here? Seriously? > And further, is there any language which is > _truly_ better (regarding code maintainability, readability and > developing ease) than C++ and as overhead-free as it? Maintainability, readability and developing ease are sufficiently dependent on *not* using things like C++ templates. Even more variadic templates! Note that for numeric applications templates do not help much. Consider the following problem. Let you have to implement some mathematical function of known algorithm and put it into a library. That latter is not possible with templates anyway is beside the point. How do you do it to work for say float, double etc? Metaprogramming you said. You could try implementing it as a template, but the parameter here is not the actual type you need to use in the computations in order to make the result accurate within the precision of the type number. In C++ you cannot even learn the precision of a template argument. In Ada at least you can (Ada Reference Manual 3.5.8). But considering: generic type Real is digits <>; -- To work with any floating-point type function Generic_Elliptic_Integral (X : Real; K : Real) return Real; The following implementation is illegal: function Generic_Elliptic_Integral (X : Real; K : Real) return Real is type Internal is digits Real'Digits * 2; -- You cannot do that! begin ... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de