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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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!postnews.google.com!f42g2000yqn.googlegroups.com!not-for-mail From: =?ISO-8859-1?Q?Elias_Salom=E3o_Helou_Neto?= Newsgroups: comp.lang.ada Subject: Re: Efficiency of code generated by Ada compilers Date: Tue, 10 Aug 2010 06:52:21 -0700 (PDT) Organization: http://groups.google.com Message-ID: <8349c981-4dca-49dc-9189-8ea726234de3@f42g2000yqn.googlegroups.com> References: NNTP-Posting-Host: 143.107.183.162 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1281448341 32666 127.0.0.1 (10 Aug 2010 13:52:21 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 10 Aug 2010 13:52:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f42g2000yqn.googlegroups.com; posting-host=143.107.183.162; posting-account=8auP9QoAAACkSx2qxJhP83KA6-tg78E8 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13061 Date: 2010-08-10T06:52:21-07:00 List-Id: On Aug 7, 4:53=A0am, "Dmitry A. Kazakov" wrote: > On Fri, 6 Aug 2010 13:21:48 -0700 (PDT), Elias Salom=E3o 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. Yes, I know that. I am, however, writing code within that 1% of applications that would be tremendously affected if there is no way to access arrays with no range checking. So I am asking very precisely: does Ada allow me to do non range-checked access to arrays? > > > 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. This is what attracted me, but, as you may guess, I cannot spend months learning the language if I am not sure about some very specific issues, such non RC array indexing. > > 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 informatio= n > can be used in optimization. All right. This one is easy to believe! > > 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. What exactly does it mean? Is it something like run-time instantiation? > > 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. Hum... I intend to write an efficient n-dimensional matrix. This would leave to me the option to individually write element accessing code for each possible instance of my generic class if I wish to make it through a member function (or whatever is equivalent to that in Ada) that takes as many elements as there are dimensions, right? > > 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? I did not mean that, but I am terribly sorry for this paragraph since, as Gene commented, this is a truly unreasonable question. I am sure there are plenty of reasons why Ada should exist that goes far beyond the questions I pointed out :) - no I am not a troll. > > 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 depende= nt > on *not* using things like C++ templates. Even more variadic templates! Could you elaborate on that? I do not agree and I do have lots of experience in writing and maintaining template code in C++. They are as easy to read, maintain and develop as any C++ code, or should I say as difficult? So, the point in C++ difficulty is not quite templated code, but rather everything else in the language :) Even if it is difficult, I like C++, but I have long been feeling that there _must_ be better options. I am right now looking for the right one. > Note that for numeric applications templates do not help much. Consider t= he > following problem. Let you have to implement some mathematical function o= f > known algorithm and put it into a library. That latter is not possible wi= th > templates anyway is beside the point. You seem to imply that templated code cannot be part of a library, but it definitely can. Just consider the possibility of distributing the source, which is what I wish to do. STL does just that. Even if you do not want to go open source, it is easier to write the code once and instantiate it for every type your users are supposed to use, maybe wrapped within some overloaded function. > How do you do it to work for say > float, double etc? Metaprogramming you said. You could try implementing i= t > as a template, but the parameter here is not the actual typ= e > 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. You can! There is the std::numeric_limits template that does allow you to learn nearly everything you need about the numeric type "number". You can even specialize this template to your own user- defined type so it will act as a fundamental arithmetic type in most aspects. > In Ada at least you can (Ada Reference > Manual 3.5.8). But considering: > > generic > =A0 =A0type Real is digits <>; =A0-- 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 > =A0 =A0type Internal is digits Real'Digits * 2; =A0-- You cannot do that! > begin > =A0 =A0... I don't fully understand the code, but it does seem to be very intuitive. What does type Real is digits <>; mean? Is "digits" a keyword of the language? I guess Ada groups fundamental types in categories and "digits" mean we must use some floating point type as the template argument, right? It sounds like a good idea, specially if things like that could be done for user defined types, i.e., if I can define my own type that "is digits <>". > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de