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,ad4585f2971e47c5 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!news.mixmin.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 19 Feb 2011 07:05:10 -0600 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: Need some light on using Ada or not Date: Sat, 19 Feb 2011 13:07:58 +0000 Reply-To: brian@shapes.demon.co.uk Message-ID: <7ibvl6tn4os3njo3p4kek9kop44nke3n7t@4ax.com> References: <4d5ef836$0$23753$14726298@news.sunsite.dk> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-Vkuxw0WgAWKvYmIoxWdfk/mRl+CB/C+wm5CldApfkoIOQ73FTWZBDPhTfH0gGOgpq8yGyyxDYx5Otyq!4UsnCYxfWUVHThgNZhPfNk0oan0woKO7tJMi9ngRyxdMU8WwdDk8WFTGokNe1MuHHN0O7FXWNKZI!JYw= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 6212 Xref: g2news2.google.com comp.lang.ada:18418 Date: 2011-02-19T13:07:58+00:00 List-Id: On 18 Feb 2011 22:52:38 GMT, "Luis P. Mendes" 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