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 Path: g2news2.google.com!news4.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!news.swapon.de!nuzba.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Access types as parameters Date: Thu, 13 Aug 2009 23:07:47 -0500 Organization: Jacob Sparre Andersen Message-ID: References: <521c4843-d40f-4545-9e80-ca725e847090@h21g2000yqa.googlegroups.com> <8410fc60-9b8a-4f82-92fc-622a6bbe5931@i18g2000pro.googlegroups.com> <8880c3d0-a07f-4d4e-ac87-372014598576@d15g2000prc.googlegroups.com> <4a83d018$0$26303$4f793bc4@news.tdc.fi> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1250222936 18806 69.95.181.76 (14 Aug 2009 04:08:56 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 14 Aug 2009 04:08:56 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news2.google.com comp.lang.ada:7750 Date: 2009-08-13T23:07:47-05:00 List-Id: "Niklas Holsti" wrote in message news:4a83d018$0$26303$4f793bc4@news.tdc.fi... > Randy Brukardt wrote: > >> You almost never want redispatching > > That's interesting as my experience is the opposite: Most of the calls > between primitive methods in my code use redispatching. > > My tagged types tend to have a hierarchy of primitive operations, for > example an Overall_Method that implements some functionality by a sequence > of calls to a Detail_Method. Some derived types override Detail_Method, so > the call from Overall_Method to Detail_Method must redispatch. Some other > (or the same) derived types override Overall_Method, so it cannot be > class-wide. It seems to me that one or the other of these routines ought to be class-wide, the fact that neither can be is a design problem. But YMMV. The primary reason that you don't (usually) want redispatch is that it is hard to guarentee the semantics of a routine if it re-dispatches and thus calls routines with unknown semantics. For Ada predefined libraries, we went so far as to create a rule that calls do *not* redispatch - A(3.1/3) (You'll have to look in the draft RM to see that one, since it was added in response to a question on Ada 2005: see http://www.adaic.com/standards/1zrm/html/RM-A.html). To quote: "For a descendant of a language-defined tagged type, the implementation shall ensure that each inherited language-defined subprogram behaves as described in this International Standard. In particular, overriding a language-defined subprogram shall not alter the effect of any inherited language-defined subprogram." In short, don't redispatch in language-defined routines. Re-dispatching is really only safe semantically if you can guarentee that the functionality of any overriding is a superset of that of the base operation. But of course there is no way to guarentee that in Ada; even if you intend it to be true and write the code with calls to the parent routine, raising an exception can cause it to become false (by skipping the parent routine). Of course, sometimes the semantics aren't very firmly defined, and redispatching works fine. As I said, YMMV. Randy.