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,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!not-for-mail From: kevin.cline@gmail.com (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: 23 Sep 2004 02:17:01 -0700 Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 24.219.97.214 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1095931022 28095 127.0.0.1 (23 Sep 2004 09:17:02 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 23 Sep 2004 09:17:02 +0000 (UTC) Xref: g2news1.google.com comp.lang.ada:3997 Date: 2004-09-23T02:17:01-07:00 List-Id: Brian May wrote in message news:... > >>>>> "Simon" == Simon Wright writes: > > Simon> James Alan Farrell writes: > >> The things that make a language a "good" language are many and > >> complex, and are different in different circumstances. If I > >> need a small utility that compares lines in different text > >> files, I find perl much easier than Ada. On the other hand, if > >> I have a very large project that must always perform > >> "correctly", I've not found a language that can beat Ada. > > Simon> Even I would accept that Ada may just not be the best > Simon> language in the world for text processing! > > Perl has high level primitive for: > > * <> operator > > * built in $hash{$index} > > * split function > > C++ > > * doesn't have the <> operator so the files have to be opened manually. > > * uses std::map instead of $hash{$index} which is more verbose for extra > type checking. The map has to be declared, but then you can simply say map[key]. > > * requires both word_list (std::list) and word_map (std::map), I am > guessing this is because it is not possible to have an ordered > std::map. (as distinct from the perl solution). Actually, the map keys are ordered, but the program prints the words in order from most to least frequent, so you need to resort on the map values. > > * doesn't have the split operator, so needs a get_word function. That was the most painful part. I spent a while trying to figure out if it could be done using the >> operator by modifying the definition of whitespace, but gave up. That part of the library could be improved. Alternatively, I could have used boost::regex and saved a dozen lines or so. > ADA > > * doesn't have the <> operator so files have to be opened manually. > > * the insert function seems complicated, not convinced this is > required (maybe it is). > > * has a find_token function which somewhat simplifies the C++ code for > get_word, but not quite as simple as the perl code. No, because strings are manipulated as arrays instead of simple types. Instead of simply returning a string, find_token returns indices into a character array. Handling strings as array slices is extremely awkward. It's hard to write, and hard to read. And it's error-prone. Ada will protect you from buffer overruns, but it can't protect you from off-by-one errors that misplace a character. String handling in Ada is only a slight improvement over C's strcpy/strcat mess. > > * has more overhead because of increased type checking. > > > In the Ada case, putting almost everything in one big huge, ugly, > function doesn't help readability (maybe this is a bit extreme, but > one of my university lecturers insisted that no > function/procedure/subroutine/whatever-you-call-it should be longer > then a page). He's right, and I think even a page is much too long. I generally try to keep mine at about ten lines or less. When they get bigger than that, I split them into smaller routines. Do this and you will generally find that the total line count will decrease, because those small functions get reused more than you might intially expect.