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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit From: Brian May Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) References: Date: Thu, 23 Sep 2004 10:03:19 +1000 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:03Q4YjYTuWra+avjTtOurMs+CJw= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: dsl-202-173-153-89.vic.westnet.com.au X-Trace: news.melbourne.pipenetworks.com 1095897790 202.173.153.89 (23 Sep 2004 10:03:10 +1000) X-Complaints-To: abuse@pipenetworks.com X-Abuse-Info: Please forward all headers to enable your complaint to be properly processed. Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed-east.nntpserver.com!nntpserver.com!news1.optus.net.au!optus!news.mel.connect.com.au!news.alphalink.com.au!news.melbourne.pipenetworks.com!not-for-mail Xref: g2news1.google.com comp.lang.ada:3976 Date: 2004-09-23T10:03:19+10:00 List-Id: >>>>> "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. * 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). * doesn't have the split operator, so needs a get_word function. 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. * 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). I would say this is a good example of why programming in Ada does not necessarily mean excellent code. If I were writing this, I would try splitting along similar lines as the perl code, e.g.: (disclaimer: not tested; syntax may not be exactly correct; still you should get the general idea). with Input; with Word; with Word_Map; with Ada.Text_IO. procedure Wordcount is Line : String; Word : String; n : Integer := 0; begin while Input.More do Word.Set_Line(Input.Get_Line); while Word.More do Word_Map.Add_Word(Word.Get_Word); Word.Next; end while; Input.Next; end while; Word_Map.sort; while Word_Map.More and n <= 10 then Put(Word_Map.Get_Word); Put(' '); Put(Word_Map.Get_Count, Width => 0); New_Line; Word_Map.Next; n := n + 1; end; end Wordcount; I think something like this could be just as readable as the perl code (you might argue that it is more readable), even though there are extra packages required that I haven't considered, and the total line count is likely to be higher. Sure, some of the packages could also be more generic and/or task safe (e.g. no objects or iterators used), but a generic solution wasn't required so I didn't bother. Also it is perhaps worth noting that while the perl code seems simple now, if the specifications were to incrementally change, the resultant code may not be so simple. -- Brian May