comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: How to test object hierarchy
Date: Sun, 21 Dec 2003 20:19:37 -0500
Date: 2003-12-21T20:19:37-05:00	[thread overview]
Message-ID: <X62dnTGVeOQ323ui4p2dnA@comcast.com> (raw)
In-Reply-To: <49cbf610.0312211158.87338af@posting.google.com>

Dmytry Lavrov wrote:

>>I think that IF Ada should have multiple dispatch on different types...

In Ada, if and where you need it, you can get multiple dispatching. 
There are of course many different patterns that correspond to multiple 
dispatching, and if you want the most general pattern:

function "+" (L, R: Object) return Object;

Where unlike normal Ada, L, R and the return value can be different 
specific types.  This can be done, but you actually have to do some 
extra work "under the covers."

Normally you would declare the visible "+" as:

function "+" (L: Object; R: Object'Class) return Object'Class;

Then in the private part you would have a function which is called by 
the visible "+" but dispatches on the second parameter, and result type:

function Add (L: Object'Class; R: Object) return Object;

Or L may be of some general representation type.  But from experience, 
doing all this is a lot of work, and you don't want to even think about 
extending Object beyond the initial set of specific types.  You don't 
have to rethink the entire structure when you do that, but it may be the 
only way to produce something that is understandable to humans.

The Multics PL/I compiler has (had?) a horrible example of this.  PL/I 
has implicit conversions between types and all sorts of conversions you 
wouldn't expect are defined.  Including various flavors of literals, the 
PL/I compiler front end had 17 different cases to deal with. Well, 
actually, that was for each parameter.  So there were really 289 cases 
that could come up.  In practice only about 60 were implemented 
specificly, the rest were defaulted by using an "any-to-any" conversion 
routine on one or the other operand.  Most of the defaulted cases 
involved adding (or whatever operation you were implementing) two 
literals, so everything could be done at compile time anyway.

So can you do something like this in Ada.  Sure.  Can you maintain your 
sanity while doing it?  Questionable whether you are doing it in Ada, 
PL/I, assembler, or whatever.  The polynomial explosion of cases may be 
capable of being handled by quite clever code, but you still end up 
slogging through testing all those bizarre cases anyway.  (And in PL/I, 
you don't have to spend much time dreaming up test cases for adding bit 
strings to decimal numbers, or adding booleans to character strings 
before you start screaming. ;-)


The much, much, more common, and much easier to deal with case is where 
you want to dispact separately on two or more independent parameters. 
I've actually used that.

-- 
                                           Robert I. Eachus

"The war on terror is a different kind of war, waged capture by capture, 
cell by cell, and victory by victory. Our security is assured by our 
perseverance and by our sure belief in the success of liberty." -- 
George W. Bush




  reply	other threads:[~2003-12-22  1:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-18 18:24 How to test object hierarchy Pierre Favier
2003-12-19  0:15 ` Stephen Leake
2003-12-19  7:45   ` Pierre Favier
2003-12-19 10:53 ` Dmitry A. Kazakov
2003-12-19 14:35   ` Hyman Rosen
2003-12-19 17:07     ` Dmitry A. Kazakov
2003-12-19 23:26     ` Robert A Duff
2003-12-20 18:20       ` Robert I. Eachus
2003-12-19 17:25   ` Georg Bauhaus
2003-12-20 11:13     ` Dmitry A. Kazakov
2003-12-21  4:34       ` Georg Bauhaus
2003-12-21 13:43         ` Dmitry A. Kazakov
2003-12-21 19:58           ` Dmytry Lavrov
2003-12-22  1:19             ` Robert I. Eachus [this message]
2003-12-22 10:09               ` Dmitry A. Kazakov
2003-12-22 17:33                 ` Robert I. Eachus
2003-12-23 10:49                   ` Dmitry A. Kazakov
2003-12-22 10:05             ` Dmitry A. Kazakov
2003-12-19 17:24 ` Nick Roberts
replies disabled

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