From: Elias Salomão Helou Neto on
I would like to know how does code generated by Ada compilers compare
to those generated by C++. I use C++ for numerical software
implementation, but I am trying to find alternatives. One thing,
however, I cannot trade for convenience is efficiency. Will Ada
compiled code possibly be as efficient as that generated by C++
compilers?

Also, I do need to have something similar to C++ "templated
metaprogramming" techniques. 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?

If any of the above questions is to be negatively answered, I ask: why
does Ada even exist? 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?

Thank you in advance,
Elias.
From: (see below) on
On 06/08/2010 21:21, in article
f3c0cf89-6993-4b83-b4fe-8a920ce23a14(a)f6g2000yqa.googlegroups.com, "Elias
Salom�o Helou Neto" <eshneto(a)gmail.com> wrote:

> I would like to know how does code generated by Ada compilers compare
....
> Elias.

Troll alert.

--
Bill Findlay
<surname><forename> chez blueyonder.co.uk


From: Shark8 on
On Aug 6, 2:21 pm, Elias Salomão Helou Neto <eshn...(a)gmail.com> wrote:
> I would like to know how does code generated by Ada compilers compare
> to those generated by C++. I use C++ for numerical software
> implementation, but I am trying to find alternatives. One thing,
> however, I cannot trade for convenience is efficiency. Will Ada
> compiled code possibly be as efficient as that generated by C++
> compilers?
>
> Also, I do need to have something similar to C++ "templated
> metaprogramming" techniques. 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?
>
> If any of the above questions is to be negatively answered, I ask: why
> does Ada even exist? 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?
>
> Thank you in advance,
> Elias.

Well, it really depends on what you mean by "efficient." If you're
terming things like accessing invalid indecies of arrays as
'efficient' "because there's no time wasted on range-checking" then
you're *REALLY* in the wrong place... however, if you're terming
'efficient' as there are no range-checks generated because the
variable indexing the array is constrained to valid values, well then
you'd be quite welcome here.

{GCC has an Ada front-end, so in-theory Ada and C++ gcc-compiled
programs should have very-near the same profiles; this is, however,
not taking into any consideration for Ada's stronger type-system and
impacts of compile-time checks & optimizations that allows.} As for
me, I am rather strongly opinionated that things like range-checking
should [always] be done, unless there is some VERY compelling and
definable reason not to. {Say you're making a Stream-interpreter where
the stream is operation-instructions for some robotic component,
except the stream itself also contains control-commands for sub-
unit[s] that have a different/larger/disjoint range.}

Templates, as I understand them in C++ are roughly analogous to Ada's
generic-system; I never got into C++'s templates and am relatively new
to Ada, so I'll let someone with more experience address that aspect.
From: Dmitry A. Kazakov on
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<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. 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
From: Gene on
On Aug 6, 4:21 pm, Elias Salomão Helou Neto <eshn...(a)gmail.com> wrote:
> I would like to know how does code generated by Ada compilers compare
> to those generated by C++. I use C++ for numerical software
> implementation, but I am trying to find alternatives. One thing,
> however, I cannot trade for convenience is efficiency. Will Ada
> compiled code possibly be as efficient as that generated by C++
> compilers?
>
> Also, I do need to have something similar to C++ "templated
> metaprogramming" techniques. 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?
>
> If any of the above questions is to be negatively answered, I ask: why
> does Ada even exist? 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?

My experience is that GNAT produces code very similar to GCC-compiled C
++ for equivalent programs.

In some cases, a built-in Ada construct will generate better code than
a "hand-coded" equivalent in C++. An example I ran into recently was
incrementing a modular type. In Ada, you say I := I + 1;, and the
compiler takes care of "wrapping" to zero. In C++, I've frequently
seen people write i = (i + 1) % n; to simulate the same operation in
the absence of modular types. In this case, GCC/C++ generates a div/
mod instruction, which is very expensive. GNAT generates if (n ==
const(n - 1)) i = 0; else i++; In the past, I have seen examples where
Ada array indexing was much more efficient than C++, apparently
because GCC could not make needed inferences about aliasing.

In some cases, GNAT "compiles in" error checking that you must turn
off to get the equivalent GCC code. There's no down side in this, as
it means you never had to write the error checking (overflows, array
bounds, etc.), which is much more expensive and error-prone than
letting GNAT do it for you (and then possibly turning selected bits
off in the 1% of cases where it makes a difference). And of course
it's even more expensive never to check for errors at all, adding risk
of an undiscovered bug in production, which an unfortunate amount of C+
+ code does.

Finally, there are a few places where GCC/C++ does produce somewhat
better code than GNAT simply because there are more people tweaking
the C++ portion of GCC. I can't recall ever seeing the reverse
occur. So it goes. There will always be differences among compilers.

Design and idiomatic coding in Ada wouldn't benefit from variadic
functions and procedures. Various combinations of overloading, named
parameters with default values, and aggregates accomplish the same
objectives in a more coherent manner. Certainly efficient variadic
functions would be useful in C++ because they're specified in the
libraries.

You were asking reasonable questions until the last paragraph. So I'll
stop here. But see comp.lang.c where C zealots frequently make
similar assertions about C with respect to C++.