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 Path: g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!news-FFM2.ecrc.net!rcn!feed3.news.rcn.net!not-for-mail Sender: jsa@rigel.goldenthreadtech.com Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) References: <11b4d.3849$d5.30042@newsb.telia.net> From: jayessay Organization: Tangible Date: 23 Sep 2004 15:10:36 -0400 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: DXC=gPJ]_?EBX[LOLBBm>Hmd>B0R]m=BkYWIG:6bU3OT9S9JFj]OOm`_0hC^aM2i8keRmM^9fnNeT1:SD X-Complaints-To: abuse@rcn.com Xref: g2news1.google.com comp.lang.ada:4035 Date: 2004-09-23T15:10:36-04:00 List-Id: kevin.cline@gmail.com (Kevin Cline) writes: > Bj�rn Persson > > Kevin Cline wrote: > > > > > Ada/Charles 158 lines, 9 files > > > C++ 76 lines > > > Perl 14 lines > > > > Neat. Now let's take three identical persons who haven't seen this > > program before, give them one version each, and see how long it takes > > them to understand it. > > In other words: What matters is how easy the program is to read and > > maintain. Here is a quick hack Common Lisp version. It is 11 "lines". You could get rid of a couple more (defun word-count (file-spec &key (wordpat (compile-pattern "[A-Za-z]+"))) (let ((words->count (make-hash-table :test #'equal :size 10007))) (with-open-file (in file-spec :direction :input) (loop for line = (read-line in nil nil) while line do (replace-match :source line :target wordpat :every-occurance t :replacement #'(lambda (word) (incf (gethash word words->count 0)) "")))) (format t "~{~A~^~%~}" (subseq (sort (all (w c) :in words->count) #'> :key #'second) 0 10)))) This also does all the checking of the C++ and Ada versions as well. > I quite agree, and on that score the Perl code wins hands down. I don't much like Perl (too much line noise), but I still think you are right here. It took just a glance at the Perl to know what the basic "spec" was (including just printing the top ten). OTOH, I think the above Lisp is significantly more readable than any of them as it is both short and very descriptive. > It's pretty hard to make the case that this Ada code: > > procedure Insert (Word : String) is > I : Wordcount_Maps.Iterator_Type; > B : Boolean; > type Element_Access is access all Wordcount_Maps.Element_Subtype; > > for Element_Access'Storage_Size use 0; > > function To_Access is new Wordcount_Maps.Generic_Element > (Element_Access); > > begin -- Insert > Insert (Map, To_Lower (Word), 0, I, B); > declare E : Wordcount_Maps.Element_Subtype renames To_Access > (I).all; > begin > E := E + 1; > end; > end Insert; > > is easier to understand than the corresponding C++ code: > ++concordance[word]; > > or the corresponding Perl code: > ++$count{$word}; Or the non library, out of the box Lisp: (incf (gethash word words->count 0)) What's more, it will be at least as fast as the C++ or Ada. /Jon -- 'j' - a n t h o n y at romeo/charley/november com