comp.lang.ada
 help / color / mirror / Atom feed
From: "Elias Salomão Helou Neto" <eshneto@gmail.com>
Subject: Re: Efficiency of code generated by Ada compilers
Date: Tue, 10 Aug 2010 06:52:21 -0700 (PDT)
Date: 2010-08-10T06:52:21-07:00	[thread overview]
Message-ID: <8349c981-4dca-49dc-9189-8ea726234de3@f42g2000yqn.googlegroups.com> (raw)
In-Reply-To: h25ogo4zscyo$.y5kkbnqkhgn3.dlg@40tude.net

On Aug 7, 4:53 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> 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.

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 information
> 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 dependent
> 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 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.

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 it
> as a template<class number>, 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.

You can! There is the std::numeric_limits<class number> 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
>    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
>    ...

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




  reply	other threads:[~2010-08-10 13:52 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-06 20:21 Efficiency of code generated by Ada compilers Elias Salomão Helou Neto
2010-08-06 20:24 ` (see below)
2010-08-06 23:14 ` Shark8
2010-08-07  7:53 ` Dmitry A. Kazakov
2010-08-10 13:52   ` Elias Salomão Helou Neto [this message]
2010-08-10 14:24     ` Shark8
2010-08-10 14:28     ` Shark8
2010-08-10 15:01     ` Robert A Duff
2010-08-10 15:14       ` Yannick Duchêne (Hibou57)
2010-08-10 18:32         ` Robert A Duff
2010-08-10 15:10     ` Georg Bauhaus
2010-08-10 15:32     ` Dmitry A. Kazakov
2010-08-10 22:26     ` Randy Brukardt
2010-08-20  7:22       ` Yannick Duchêne (Hibou57)
2010-08-08 14:03 ` Gene
2010-08-08 15:49   ` Robert A Duff
2010-08-08 17:13     ` Charles H. Sampson
2010-08-08 18:11       ` Dmitry A. Kazakov
2010-08-08 20:51       ` Robert A Duff
2010-08-08 22:10         ` (see below)
2010-08-08 22:22           ` Robert A Duff
2010-08-09  4:46         ` Yannick Duchêne (Hibou57)
2010-08-09  5:52         ` J-P. Rosen
2010-08-09 13:28           ` Robert A Duff
2010-08-09 18:42             ` Jeffrey Carter
2010-08-09 19:05               ` Robert A Duff
2010-08-10 10:00                 ` Jacob Sparre Andersen
2010-08-10 12:39                   ` Robert A Duff
2010-08-09 19:33             ` Yannick Duchêne (Hibou57)
2010-08-09 21:42               ` Robert A Duff
2010-08-10 12:26         ` Phil Clayton
2010-08-10 12:57           ` Yannick Duchêne (Hibou57)
2010-08-10 14:03             ` Elias Salomão Helou Neto
2010-08-10 14:27               ` Yannick Duchêne (Hibou57)
2010-08-10 22:50                 ` anon
2010-08-10 23:28                   ` Yannick Duchêne (Hibou57)
2010-08-10 23:38                     ` Yannick Duchêne (Hibou57)
2010-08-11  7:06                       ` Niklas Holsti
2010-08-11 11:58                         ` anon
2010-08-11 12:37                           ` Georg Bauhaus
2010-08-11 13:13                         ` Robert A Duff
2010-08-11 23:49                           ` Randy Brukardt
2010-08-10 14:31               ` Shark8
2010-08-11  7:14               ` Charles H. Sampson
2010-08-11  6:42         ` Charles H. Sampson
2010-08-08 22:35     ` tmoran
2010-08-09 13:53       ` Robert A Duff
2010-08-09 17:59         ` tmoran
2010-08-09 19:36           ` Yannick Duchêne (Hibou57)
2010-08-09 21:38             ` Robert A Duff
2010-08-11  7:42       ` Charles H. Sampson
2010-08-11 13:38         ` Robert A Duff
2010-08-12  7:48           ` Charles H. Sampson
2010-08-12  8:08             ` Ludovic Brenta
2010-08-12 17:10               ` Charles H. Sampson
2010-08-12 18:06                 ` Jeffrey Carter
2010-08-11 18:49         ` Simon Wright
2010-08-12  7:54           ` Charles H. Sampson
2010-08-12  8:36             ` Dmitry A. Kazakov
2010-08-12 11:04             ` Brian Drummond
2010-08-12 19:23             ` Simon Wright
2010-08-12 20:21               ` (see below)
2010-08-13 15:08                 ` Elias Salomão Helou Neto
2010-08-13 15:10                   ` Elias Salomão Helou Neto
2010-08-13 18:01                     ` Georg Bauhaus
2010-08-13 19:52                       ` Robert A Duff
2010-08-14  9:44                         ` Georg Bauhaus
2010-08-13 20:22                     ` Robert A Duff
2010-08-14  1:34                       ` Randy Brukardt
2010-08-14  7:18                         ` anon
2010-08-13 21:57                     ` Jeffrey Carter
2010-08-13 22:37                       ` Yannick Duchêne (Hibou57)
2010-08-13 22:43                         ` Yannick Duchêne (Hibou57)
2010-08-13 23:29                         ` tmoran
2010-08-14  0:02                           ` Yannick Duchêne (Hibou57)
2010-08-14  0:16                             ` (see below)
2010-08-14 10:47                             ` Brian Drummond
2010-08-14 13:58                               ` Yannick Duchêne (Hibou57)
2010-08-15  0:23                                 ` Brian Drummond
2010-08-14 14:51                               ` (see below)
2010-08-15  0:58                                 ` Brian Drummond
2010-08-15  1:58                                   ` (see below)
2010-08-15 10:31                                     ` Brian Drummond
2010-08-13 15:37                   ` Dmitry A. Kazakov
2010-08-16 13:29                     ` Elias Salomão Helou Neto
2010-08-16 14:09                       ` Dmitry A. Kazakov
2010-08-18 14:00                         ` Elias Salomão Helou Neto
2010-08-18 16:38                           ` Dmitry A. Kazakov
2010-08-19 18:52                             ` Elias Salomão Helou Neto
2010-08-19 19:48                               ` Dmitry A. Kazakov
2010-08-13 16:58                   ` (see below)
2010-08-14 16:13                   ` Charles H. Sampson
2010-08-16 13:45                     ` Elias Salomão Helou Neto
2010-08-15 12:32 ` Florian Weimer
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox