comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Access types as parameters
Date: Thu, 13 Aug 2009 23:07:47 -0500
Date: 2009-08-13T23:07:47-05:00	[thread overview]
Message-ID: <h62o0n$ibm$1@munin.nbi.dk> (raw)
In-Reply-To: 4a83d018$0$26303$4f793bc4@news.tdc.fi

"Niklas Holsti" <niklas.holsti@tidorum.invalid> 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.






  parent reply	other threads:[~2009-08-14  4:07 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-17  8:39 Access types as parameters Rick
2009-07-17 15:03 ` Adam Beneschan
2009-07-17 16:28   ` Hibou57 (Yannick Duchêne)
2009-07-17 23:25     ` rickduley
2009-07-18  1:03       ` Randy Brukardt
2009-07-19 22:57         ` rickduley
2009-07-20  0:10           ` John B. Matthews
2009-07-20  8:13           ` Dmitry A. Kazakov
2009-07-21  0:34           ` Randy Brukardt
2009-07-21 14:34           ` Adam Beneschan
2009-07-23  2:11             ` Stephen Leake
2009-08-11 23:41               ` Randy Brukardt
2009-08-12  2:22                 ` Stephen Leake
2009-08-13  1:06                   ` Randy Brukardt
2009-08-13  8:34                     ` Niklas Holsti
2009-08-13  9:15                       ` Dmitry A. Kazakov
2009-08-13 20:13                         ` Niklas Holsti
2009-08-13 21:07                           ` Dmitry A. Kazakov
2009-08-14  9:27                             ` Niklas Holsti
2009-08-14 10:36                               ` Dmitry A. Kazakov
2009-08-14 16:03                                 ` Niklas Holsti
2009-08-15  9:47                                   ` Dmitry A. Kazakov
2009-08-15 19:19                                     ` Niklas Holsti
2009-08-16  8:32                                       ` Dmitry A. Kazakov
2009-08-16  9:52                                         ` Niklas Holsti
2009-08-16 12:38                                           ` Dmitry A. Kazakov
2009-08-16 13:21                                             ` Niklas Holsti
2009-08-16 17:58                                               ` Dmitry A. Kazakov
2009-08-14  4:07                       ` Randy Brukardt [this message]
2009-08-14 10:22                         ` Niklas Holsti
2009-08-18 12:22                     ` Stephen Leake
replies disabled

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