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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,760a0492b97ae06e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-21 17:19:40 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!news-xfer2.atl.newshosting.com!216.166.71.118.MISMATCH!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 21 Dec 2003 19:19:38 -0600 Date: Sun, 21 Dec 2003 20:19:37 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to test object hierarchy References: <93172edb.0312181024.9a536b2@posting.google.com> <49cbf610.0312211158.87338af@posting.google.com> In-Reply-To: <49cbf610.0312211158.87338af@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-n7lmyOnX4aPU+51io4Els0Yqz2vluDFJH0ZFs+l+DbnwEwGNxJogBtF9G1Y69dZM8hD1EP2NegMMmOi!VDh/c9Aln+SdNR6zijevExgmMFtqj3evr9vjyxsDd6urDmR/YdqjVqAd+Vl4Qg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:3682 Date: 2003-12-21T20:19:37-05:00 List-Id: 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