comp.lang.ada
 help / color / mirror / Atom feed
From: Brian Drummond <brian_drummond@btconnect.com>
Subject: Re: Need some light on using Ada or not
Date: Sat, 19 Feb 2011 13:07:58 +0000
Date: 2011-02-19T13:07:58+00:00	[thread overview]
Message-ID: <7ibvl6tn4os3njo3p4kek9kop44nke3n7t@4ax.com> (raw)
In-Reply-To: 4d5ef836$0$23753$14726298@news.sunsite.dk

On 18 Feb 2011 22:52:38 GMT, "Luis P. Mendes" <luislupeXXX@gmailXXX.com> wrote:

>Hi,
>
>I have two projects to work, one of them in the data mining field and 
>another regarding xml parsing.
>I've been learning C++ (from a Python, Pascal, VB background), due to it 
>being fast (sure it depends on the implementation) and because it has a 
>lot of libraries.
>
>But I find C++ a very complex language and Ada appeals to me specially 
>for its overall safety.  Or maybe also because I don't like to go with 
>majorities... :-)

One other Ada advantage is not often mentioned, but will strongly appeal once
you start using it...

I believe the reason it is not often mentioned is because Ada texts tend to
pre-date current trends in software development (agile programming, refactoring
and so on).

I find Ada very very easy to refactor, and quite safe too, because the kinds of
bugs that you accidentally introduce while refactoring are the kinds of bugs
that the compiler is good at catching; visibility rules, etc.

Moving code into packages or into local procedures ... just works, in ways that
C++ would rarely allow, usually failing in the most obscure ways in my
experience. When I change the structure of a program, I detest having to change
every other . into -> for example.

Another example : moving an array from local variable (the stack) to the heap
(after I increased its size and hit a stack size limit) meant I had to refer to
it through an access type, instead of directly. Instead of "my_array(I,J,K)" I
was faced with changing every reference to "my_array_ptr.all(I,J,K)" ...
However...
	my_array : big_array_type renames my_array_ptr.all;
and I was done. 
(Apologies to the regulars; I've told that story before.
But it was one of the incidents that sold me on Ada's ease of use)

>I have some questions, however, that I'd like to be answered:
>1. If Ada is more type safe and restricted than C++, how can it be 
>significantly slower?
>Please see: http://shootout.alioth.debian.org/u64q/benchmark.php?
>test=all&lang=gnat
>where for some tests, Ada is 2x, 3x, 4x and 5x slower.

Two possible reasons; both come down to the relative number of people developing
for both languages.

(1) the C++ compiler may be more highly developed. Granted that much of gcc is
common to both, that may not be the real issue.

(2) The C++ shootout code examples may be more highly developed.
Since the majority of those examples show approximate parity while a
(substantial) minority favour C++, I would suspect this. To justify it properly
would take a case-by-case analysis.  But in a quick look at the 4x slower
results, one stands out like a sore thumb...

binary-trees 			(last 4 columns are CPU usage)
Ada 2005 GNAT	37.45	37.47	198,132	 955	  0% 0% 100% 0%
C++ GNU g++	26.99	8.40	358,832 892	  87% 61% 99% 76%

Single processor, the Ada version is just 38% slower, with half the memory
footprint; probably a damn good compromise between footprint and speed.
However the C++ version exploits 4 cores. Given Ada's support for concurrent
tasks, that suggests some room for improvement...

You have some of the inside story on other examples from other posters.

>2. In C++ I can use lots of libraries. I'm thinking on data visualization 
>libraries, for example http://www.graphviz.org/Gallery/undirected/
>softmaint.html.
>I've read that Ada can use some C bindings.  Can I use any C library? 
>Some? Is it easy?

Ada can easily bind to C libraries, it's standard and well documented. 

However there already exist bindings to some graphics libraries and data
visualisation tools - look at GTKAda and QTAda for GUI and some graphics
bindings, and PLPlot for data visualisation. One of these may work for you.

C++ bindings are also possible, but with some work and (currently) some
limitations.
A GCC recent enough to support "-f-dump-ada-spec" will auto-generate an Ada spec
from C++ sources, which will save a lot of the work. (Adacore "libre" 2010 has
it; the FSF GCC 4.5.0 has not. Anyone know if it made it into 4.5.1 or 4.6.0?)

I would currently treat that binding as a starting point rather than a complete
solution.  For example, it (libre "GPL2010" from Adacore) has problems with
templates. (Especially when your well-proven C++ template library still has bugs
that Ada generics would have caught first time through the compiler!) 

One example (independent of template bugs!): I instantiated a template to create
a new class, in the C++ library. But my C++ code never actually created an
instance of the class; I only did that through the Ada binding. As a result, the
C++ compiler never created a constructor; and the link failed with "missing
constructor" (redux from a screenful of error message). I worked around this by
writing a C++ function which instantiated one of everything I needed...

- Brian



  parent reply	other threads:[~2011-02-19 13:07 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18 22:52 Need some light on using Ada or not Luis P. Mendes
2011-02-18 23:58 ` Georg Bauhaus
2011-02-19 14:25   ` Simon Wright
2011-02-19  0:20 ` Edward Fish
2011-02-20  0:13   ` Luis P. Mendes
2011-02-20  1:36     ` Marc A. Criley
2011-02-20  9:59     ` mockturtle
2011-02-20 10:37     ` Brian Drummond
2011-02-20 11:08     ` Ludovic Brenta
2011-03-01  8:10     ` Adrian Hoe
2011-03-01  8:29       ` Thomas Løcke
2011-03-04 13:34         ` Adrian Hoe
2011-02-19  8:43 ` Vadim Godunko
2011-02-19 13:07 ` Brian Drummond [this message]
2011-02-19 14:17   ` Simon Wright
2011-02-19 18:02     ` Brian Drummond
2011-02-19 18:07       ` Bill Findlay
2011-02-20 10:42         ` Brian Drummond
2011-02-19 14:36   ` Georg Bauhaus
2011-02-19 18:25     ` Brian Drummond
2011-02-20 14:34       ` Brian Drummond
2011-02-20 15:45         ` jonathan
2011-02-20 16:18           ` Brian Drummond
2011-02-20 19:49           ` Pascal Obry
2011-02-20 19:57             ` Brian Drummond
2011-02-20 20:10               ` jonathan
2011-02-20 21:15                 ` Pascal Obry
2011-02-20 21:26                   ` Vinzent Hoefler
2011-02-20 21:33                     ` Vinzent Hoefler
2011-02-20 21:36                     ` Pascal Obry
2011-02-20 21:50                       ` Vinzent Hoefler
2011-02-20 22:18                   ` jonathan
2011-02-20 22:47               ` Simon Wright
2011-02-21 12:52                 ` Brian Drummond
2011-02-21 13:44                   ` Simon Wright
2011-02-24  0:19                     ` Brian Drummond
2011-02-24  7:41                       ` Jacob Sparre Andersen
2011-02-22  2:15                   ` Shark8
2011-02-20 16:42       ` jonathan
2011-02-20 20:02         ` Brian Drummond
2011-02-20  0:20   ` Luis P. Mendes
2011-02-20 10:50     ` Brian Drummond
2011-02-20 19:54     ` Brian Drummond
2011-02-23 22:19       ` Luis P. Mendes
2011-02-24 17:06         ` Brian Drummond
2011-02-27 17:51           ` Luis P. Mendes
replies disabled

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