comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: point by point advantages of Ada
Date: Sun, 29 Dec 2002 20:09:40 GMT
Date: 2002-12-29T20:09:40+00:00	[thread overview]
Message-ID: <8EIP9.19113$p_6.1493222@bgtnsc04-news.ops.worldnet.att.net> (raw)
In-Reply-To: 1041186672.615164@ns2-ext.dcu.ie

"Colin Paul Gloster" <Colin_Paul_Gloster@ACM.org> 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





  reply	other threads:[~2002-12-29 20:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-26 21:57 point by point advantages of Ada Russ
2002-12-27 10:54 ` Ingo Marks
2002-12-27 21:11   ` Keith Thompson
2002-12-27 21:31     ` Robert A Duff
2002-12-29 18:31 ` Colin Paul Gloster
2002-12-29 20:09   ` James S. Rogers [this message]
2003-01-06 23:13     ` David Thompson
2003-01-07  1:35       ` James S. Rogers
2003-01-07 19:34         ` Randy Brukardt
2003-01-07 21:53           ` Warren W. Gay VE3WWG
2003-01-08  0:36             ` Richard Riehle
2003-01-08 17:50               ` Warren W. Gay VE3WWG
2003-01-08 20:31             ` Randy Brukardt
2003-01-13 16:37               ` Mark Biggar
2002-12-29 21:56   ` Hyman Rosen
2002-12-29 22:30     ` John R. Strohm
2002-12-29 23:16       ` Hyman Rosen
2003-01-02 14:24         ` Wes Groleau
2003-01-03  8:20           ` Hyman Rosen
2003-01-03 14:00             ` Wes Groleau
2003-01-08 20:55               ` Georg Bauhaus
2002-12-29 19:20 ` chris.danx
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox