comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: What makes a procedure call 'dispatching' in Ada?
Date: Fri, 20 Nov 2009 17:00:44 +0200
Date: 2009-11-20T17:00:44+02:00	[thread overview]
Message-ID: <4b06af42$0$6292$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <1ced67sbv38ke.1973smwq7n0uw.dlg@40tude.net>

Dmitry A. Kazakov wrote:
> On Fri, 20 Nov 2009 15:56:50 +0200, Niklas Holsti wrote:
> 
>> Dmitry has philosophical objections to redispatching, which is why he 
>> suggests that you should declare P with a class-type parameter THIS in 
>> the first place, so that A (THIS) will dispatch.
> 
> I would not call them philosophical.

Please, Dmitry, suggest a better word; perhaps "methodological"? I don't 
want to disparage your view, I understand (I think) the ideas behind it, 
although I don't value them in the same way you do.

> If you see the code like
> 
> if X = 1 then
>    ...
>    if X = 1 then
>       ...
>    end if;
>    ...
>    if X = 1 then
>       ...
>    end if;
>    ...
> 
> you start suggesting that there could be something wrong here.

In the code above, yes, because

    if X = 1 then
       if X = 1 then
          Foo;
       end if;
    end if;

is statically equivalent to the shorter

    if X = 1 then
       Foo;
    end if;

(assuming that X is not volatile, of course).

But the effects of A (THIS) and A (FOO'Class (THIS)) are different, and 
the declaration of an operation as primitive, or class-wide, also has 
significant effects on the design.

A better analogy is code like this:

    procedure John (X : Integer ..) is
    begin
       ...
       if X /= 1 then ...
       end if;
       ...
    end Jonh;

    procedure Mary (...) is
    begin
       if X = 1 then
          John (X);
       else ...
       end if;
    end Mary;

Yes, there is a double check of X, but no, it is not a redundant check.

> Re-dispatch
> is not an error it is an indication of a potential design problem. Why
> would you need to check twice the same tag? That requires an explanation in
> the design document and comments in the code.

I don't want to repeat the (long) discussion we had on this subject, but 
two comments:

- It may be that this is the first check of the tag. The operation that 
contains a (re-)dispatching call may have been called with static 
binding, not dispatching.

- The "explanation" required in the documents and code is simple, and is 
just that redispatching is used to get the most appropriate, specialized 
behaviour of this operation.

> A technical issue is that if we had tagged types of value semantics (i.e.
> classes rooted in Boolean, Integer etc), then re-dispatch could not work
> with them.

Agreed, for pure value semantics. But "object identity" is a central 
idea in object-oriented programming, so pure value semantics is doubtful 
in this area.

 > I.e. from Ada's agnostic point of view on by-value vs.
 > by-reference, re-dispatch (or speaking more generally, view
 > conversion to T'Class) is an implementation-specific kludge.

I think the parameter-passing method (by value or by reference) is not 
the central question; the question is whether we have identifiable 
objects or not. Objects could be passed by value, that is, the bits 
representing the (view of the) object could be copied, but the "value" 
would then have to include some kind of identity label (practically 
speaking, a reference), which would allow redispatching.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  reply	other threads:[~2009-11-20 15:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-20 13:15 What makes a procedure call 'dispatching' in Ada? Markus Schoepflin
2009-11-20  9:31 ` stefan-lucks
2009-11-20 14:10   ` Niklas Holsti
2009-11-20 13:27 ` Dmitry A. Kazakov
2009-11-20 13:43   ` Markus Schoepflin
2009-11-20 13:54     ` RasikaSrinivasan@gmail.com
2009-11-20 13:58     ` Markus Schoepflin
2009-11-20 14:19       ` Niklas Holsti
2009-11-21 14:07       ` Peter C. Chapin
2009-11-20 14:00     ` Niklas Holsti
2009-11-20 14:10     ` Dmitry A. Kazakov
2009-11-20 13:56 ` Niklas Holsti
2009-11-20 14:31   ` Dmitry A. Kazakov
2009-11-20 15:00     ` Niklas Holsti [this message]
2009-11-20 18:44       ` Dmitry A. Kazakov
2009-11-20 20:09         ` Niklas Holsti
2009-11-20 20:59           ` Dmitry A. Kazakov
2009-11-20 14:54 ` Ludovic Brenta
replies disabled

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