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 Path: g2news1.google.com!news1.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!rz.uni-karlsruhe.de!news.uni-stuttgart.de!carbon.eu.sun.com!new-usenet.uk.sun.com!not-for-mail From: Ole-Hjalmar Kristensen Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: 24 Sep 2004 11:44:22 +0200 Organization: Sun Microsystems Message-ID: References: NNTP-Posting-Host: ellex06.norway.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: new-usenet.uk.sun.com 1096019063 29078 129.159.114.186 (24 Sep 2004 09:44:23 GMT) X-Complaints-To: usenet@new-usenet.uk.sun.com NNTP-Posting-Date: 24 Sep 2004 09:44:23 GMT User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Xref: g2news1.google.com comp.lang.ada:4093 Date: 2004-09-24T09:44:23+00:00 List-Id: kevin.cline@gmail.com (Kevin Cline) writes: > Ole-Hjalmar Kristensen wrote in message news:... > > >>>>> "KC" == Kevin Cline writes: > > > > I usually find that my ability to create programs is limited by my > > thought process, not my typing speed :- > > Mine too. For the Perl program, the thought process was limited to > this: > > read input: while (<>) > > split into sequences of alphabetic characters: > foreach my $word (split (/[a-zA-Z]+/)) > > count words: ++$count{$word} > > sort words by frequency: sort { $map{$a} <=> $map{$b} ) keys %count > > print first 10: $n = 0; foreach ( ... ) { print ...; last if ++$n >= > 10; } > > The only bits that required much thought at all were figuring out the > right comparison function for sorting (I looked at an example), and > getting the loop exit right. The rest was written nearly > instantaneously. > > Are you really claiming that you can think of: > > procedure Insert (Word : in String) is > > procedure Increment_Count > (K : in String; > N : in out Natural) is > > pragma Warnings (Off, K); > begin > N := N + 1; > end Increment_Count; > > C : Wordcount_Maps.Cursor; > B : Boolean; > > begin -- Insert > Insert (M, Word, 0, C, B); > Update_Element (C, Increment_Count'Access); > end Insert; > > As quickly as I can think of: > ++concordance[word] > or > ++$count{$word} ? > No, not at all. But I usually write programs where the logic tends to be a bit more complicated, and where the instantiation of templates/generics and similar boiler plate is not dominating. > Multiply this 1000 times for a medium to large program and I think Ada > really suffer from unnecessary verbosity. > > It's reasonable to claim that Ada is better than C++ for > safety-critical embedded programming, but if you really want to > understand why Ada is not more popular for desktop applications I > think the evidence is here. The real question I have is why Perl and > similar high-level languages are not more popular. If I wanted something more high-level I would use Lisp, not Perl. Now consider the following implementation of a polygon clipper (an old test program I had lying around to test the relative speed of a recursive and non-recursive version of essentially the same polygon clipper) Do you really believe this program had been any more readable or easy to program in C++ or Perl? with Vector; use Vector; -- Contains basic vector and plane stuff -- Pipelined Sutherland-Hodgson type polygon clipper -- Pipeline implemented by recursive calls procedure Sutherland is -- Polygon container type Vertex_Array is array(Integer range <>) of Vector3; -- Stage in pipeline type Stage is record Pl : Plane; -- Clipping plane S : Vector3; -- Start point F : Boolean := true; -- First visit? Closing : Vector3; -- Closing point end record; -- 6 planes for frustum clipping Stages : array(1..6) of Stage; procedure Reset_Stages is begin for I in Stages'Range loop Stages(I).F := True; end loop; end Reset_Stages; -- Test if vertex is inside plane function Inside(Test_Vertex : Vector3; clip : Integer) return Boolean is begin return Inside(Test_Vertex, Stages(Clip).Pl); end Inside; -- Return intersect of vector from S to P with plane function Intersect(S : Vector3; P : Vector3; Clip : Integer ) return Vector3 is begin return Intersect(S,P,Stages(Clip).Pl); end Intersect; -- Output vertex to next stage of clipper procedure Output_Point(Clip_Stage : Integer; P : Vector3); -- Clip vertex to plane given by Clip_Stage procedure Clip_Vertex(Clip_Stage : Integer; P : Vector3) is Clipped_P : Vector3; begin -- Initialize start if first time if Stages(Clip_Stage).F then Stages(Clip_Stage).S := P; Stages(Clip_Stage).Closing := P; Stages(Clip_Stage).F := False; else if Inside(P,Clip_Stage) then if Inside(Stages(Clip_Stage).S,Clip_Stage) then Output_Point(Clip_Stage,P); else Clipped_P := Intersect(Stages(Clip_Stage).S,P,Clip_Stage); Output_Point(Clip_Stage,Clipped_P); Output_Point(Clip_Stage,P); end if; else if Inside(Stages(Clip_Stage).S,Clip_Stage) then Clipped_P := Intersect(Stages(Clip_Stage).S,P,Clip_Stage); Output_Point(Clip_Stage,Clipped_P); end if; end if; Stages(Clip_Stage).S := P; end if; end Clip_Vertex; -- Output vertex to next stage of clipper procedure Output_Point(Clip_Stage : Integer; P : Vector3) is begin if Clip_Stage >= Stages'Last then null; else Clip_Vertex(Clip_Stage + 1, P); end if; end Output_Point; procedure Empty_Pipeline is begin for I in Stages'Range loop if not Stages(I).F then Clip_Vertex(I,Stages(I).Closing); end if; end loop; end Empty_Pipeline; -- Clip polygon by clipping each vertex in turn procedure Clip_Poly(In_Poly : Vertex_Array) Is begin for I in In_Poly'Range loop Clip_Vertex(Stages'First,In_Poly(I)); end loop; Empty_Pipeline; end Clip_Poly; procedure Init_Stages is begin Reset_Stages; -- Front Stages(1).Pl := Create_Plane((0.0,0.0,0.0), (100.0,0.0,0.0), (100.0,0.0,100.0)); -- Back Stages(2).Pl := Create_Plane((100.0,100.0,0.0), (0.0,100.0,0.0), (0.0,100.0,100.0)); -- Left Stages(3).Pl := Create_Plane((0.0,100.0,0.0), (0.0,0.0,0.0), (0.0,0.0,100.0)); -- Right Stages(4).Pl := Create_Plane((100.0,0.0,0.0), (100.0,100.0,0.0), (100.0,100.0,100.0)); -- Bottom Stages(5).Pl := Create_Plane((0.0,0.0,0.0), (0.0,100.0,0.0), (100.0,100.0,0.0)); -- Top Stages(6).Pl := Create_Plane((0.0,0.0,100.0), (100.0,0.0,100.0), (100.0,100.0,100.0)); end Init_Stages; Test_Poly : Vertex_Array(1..3) := ((0.0,0.0,1.0), (150.0,200.0,1.0), (200.0,150.0,1.0)); begin Init_Stages; for I in 1..100000 loop Clip_Poly(Test_Poly); Reset_Stages; end loop; end Sutherland; -- C++: The power, elegance and simplicity of a hand grenade.