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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,982ed90dd25179ec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-29 12:19:20 PST Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.ada References: <1041186672.615164@ns2-ext.dcu.ie> Subject: Re: point by point advantages of Ada X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: <8EIP9.19113$p_6.1493222@bgtnsc04-news.ops.worldnet.att.net> Date: Sun, 29 Dec 2002 20:09:40 GMT NNTP-Posting-Host: 12.86.39.38 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1041192580 12.86.39.38 (Sun, 29 Dec 2002 20:09:40 GMT) NNTP-Posting-Date: Sun, 29 Dec 2002 20:09:40 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:32382 Date: 2002-12-29T20:09:40+00:00 List-Id: "Colin Paul Gloster" wrote in message news:1041186672.615164@ns2-ext.dcu.ie... > Back to dispatching again, below is an edited reproduction of a post made > by a C++ and Ada tool vendor: > > Date: Wed, 20 Nov 2002 12:51:31 -0000 > > "I'll back this up. I'm just in the middle of defining a "true OO" mapping > from Ada to UML. While Ada does have some useful features such as dynamic > dispatching, its cockeyed notion of sub-program roll-down is awesomely > stupid. Can you imagine a language that decides to roll-down an operation > based on the data-type of any of its parameters? but does so for only one > of > its parameters even though multiple parameters can exist? > > For instance > > package a is > -- tagged means that operations defined to > -- use this type can be overridden > type t1 is tagged > record > x : integer; > end record; > type t2 is tagged > record > y : integer; > end record; > procedure p (P1 : t1); > procedure q (P1 : t2); > procedure r (P1 : t1; P2 : t2); > procedure s (P1 : t1; P2 : t1); > end a; > > In this example, procedure p and q are both legal, but procedure r is not. > Procedure s is legal. The problem is that you've defined all these > functions > as "virtual" because one of their parameters is "tagged", but you have no > way to tell the compiler which parameter you are supposed to dispatch on. > The compiler gets confused because procedure r has 2 different > dispatchable > parameters and doesn't know which one is significant. > > By comparison, in C++, the implicit "this" parameter exists for all > non-static functions, and it is the type of "this" that is used to decide > dispatching behaviour. Nice, straightforward, and you can't get the > compiler > confused. > > Now why was it that anyone wanted to program in Ada? This is a curious complaint about Ada. The author complains that Ada cannot do something that C++ cannot do, then concludes that this shows a superiority of C++ over Ada. The solution for such a need is basically the same in both C++ and Ada. C++ provides no multiple dispatch capability. You must make such a function static, not virtual. In Ada you do the same thing. You simply define the procedure(s) taking more than one tagged type in another scope. An inner package is a common choice for another scope. package Tagged_Test is type A is tagged private; procedure Print(Item : A); type B is tagged private; procedure Print(Item : B); package Inner is procedure Print(Itema : A; Itemb : B); end Inner; private type A is tagged record Message : String(1..6) := "Type A"; end record; type B is tagged record Message : String(1..6) := "Type B"; end record; end Tagged_Test; What the original author does not mention is that C++ cannot dispatch based upon the return type of a function. This is done cleanly in Ada and not at all in C++ (or Java). In C++ you need to explicitly label a function as "virtual". The default is "static". In Java the default is the equivalent of virtual, and you must explicitly label "static" functions with the "static" keyword. In Ada functions are primitive to a type if they are declared in the same scope as the declaration of the type. That is, the "primitive" property is defined by scope, and not by the presence or absence of a reserved word. This is different from C++ and Java, but those languages also differ from each other. Such differences do not prove superiority. Jim Rogers