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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-16 17:50:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc54.POSTED!not-for-mail Message-ID: <3F67AFB9.7040001@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Is the Writing on the Wall for Ada? References: <568ede3c.0309160929.1d0d3d95@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.34.139.183 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc54 1063759831 24.34.139.183 (Wed, 17 Sep 2003 00:50:31 GMT) NNTP-Posting-Date: Wed, 17 Sep 2003 00:50:31 GMT Organization: Comcast Online Date: Wed, 17 Sep 2003 00:50:31 GMT Xref: archiver1.google.com comp.lang.ada:42590 Date: 2003-09-17T00:50:31+00:00 List-Id: Hyman Rosen wrote: > Anyway, one of the things that this approach misses from true MI > is the ability to cross-cast between pointer types without knowing > the name of a common containing class. In my Colorable/Resizable > example, I could take a 'Colorable *' and do a dynamic_cast to > 'Resizable *' on it. If the Colorable pointer was actually pointing > to a base Colorable class of a class that also contained a base > Resizable class, the cast would succeed and give me a pointer to that > Resizable class. In the access discriminant case, the best I can do > is to get the containing object and then get its Resizable part, but > that requires knowing about the type of the containing object. > > This sort of thing can be useful if you are trying to query an object > to see if it supports a particular interface, for example. I don't particularly like or use access discriminants. As you may have noticed, I prefer to use mix-ins. But as for your assertion above, I had to laugh. If you want you can try to shoot yourself in the foot that way in Ada. If the compiler can't tell at compile time that a particular cast will always succeed (or always fail) it will put code in to check and raise an exception for the type conversion. However, you have to go out of your way to have the problem. In Ada, whether you use mix-ins or access discriminants, there is no reason to do explicit casting. If you say (using my code): Set(Some_Object, Red); -- where Red is a value of type Color. you would get exactly the same result as if you said: Set(My_Colors.Colored_Object(Some_Object), Red); But in most cases where mix-ins are used in Ada, the scope where you CAN do the explicit conversion is very small, while the inherited operations are visible throughout the scope of the end type. So who cares? You don't need to do explicit casts, especially explicit casts of pointers (ugh!), so why go to the unnecessary effort? -- Robert I. Eachus "As far as I'm concerned, war always means failure." -- Jacques Chirac, President of France "As far as France is concerned, you're right." -- Rush Limbaugh