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-Thread: a07f3367d7,366b213c4abb1039 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!fi.sn.net!newsfeed2.fi.sn.net!news.song.fi!not-for-mail Date: Fri, 20 Nov 2009 17:00:44 +0200 From: Niklas Holsti Organization: Tidorum Ltd User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: What makes a procedure call 'dispatching' in Ada? References: <4b06a048$0$26319$4f793bc4@news.tdc.fi> <1ced67sbv38ke.1973smwq7n0uw.dlg@40tude.net> In-Reply-To: <1ced67sbv38ke.1973smwq7n0uw.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4b06af42$0$6292$4f793bc4@news.tdc.fi> NNTP-Posting-Host: 81.17.205.61 X-Trace: 1258729282 news.tdc.fi 6292 81.17.205.61:33605 X-Complaints-To: abuse@tdcnet.fi Xref: g2news1.google.com comp.lang.ada:8178 Date: 2009-11-20T17:00:44+02:00 List-Id: 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 . @ .