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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,7ff1de84a8945e80 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!news.unit0.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Access types as parameters Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH 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> <4a847400$0$26304$4f793bc4@news.tdc.fi> <4a852df2$0$26317$4f793bc4@news.tdc.fi> Date: Fri, 14 Aug 2009 12:36:14 +0200 Message-ID: <1jrxo2acn8evc.x3wfcmp4etbo.dlg@40tude.net> NNTP-Posting-Date: 14 Aug 2009 12:35:40 CEST NNTP-Posting-Host: 56794951.newsspool1.arcor-online.net X-Trace: DXC=03MK4L0Oe:1D]ncZ]`hZ;1ic==]BZ:af>4Fo<]lROoR1^YC2XCjHcb9?e[kjDe[Ce8DNcfSJ;bb[5FCTGGVUmh?4LK[5LiR>kg2^`B5ZRC[3c7 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7767 Date: 2009-08-14T12:35:40+02:00 List-Id: On Fri, 14 Aug 2009 12:27:02 +0300, Niklas Holsti wrote: > Dmitry A. Kazakov wrote: >> On Thu, 13 Aug 2009 23:13:39 +0300, Niklas Holsti wrote: >> >>> Dmitry A. Kazakov wrote: >>>> On Thu, 13 Aug 2009 11:34:20 +0300, Niklas Holsti wrote: >>>> >>>>> 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. >>>> Shudder... >>> Also an interesting reaction. >>> >>>> I consider re-dispatch is an indication of a language / design problem, >>>> because it is a hidden type error. An argument goes as follows. Once you >>>> have dispatched to some type T, the corresponding controlling parameter is >>>> of this type. Let we converted it to a class. If now it dispatches again to >>>> T, then that was just wasting time, if it dispatches to S /= T then it is a >>>> type error. >>> To me that is a very abstract and formalistic argument that is easily >>> weaker than the practical benefits (providing sensible but overridable >>> default behaviour while avoding code duplication) that make me use >>> redispatching. >> >> If some formal premises are not satisfied (a type consistency is one of >> them) then it is meaningless to talk about benefits. In an extreme case, >> you might have an erroneous program that occasionally yields a correct >> result. Would you see a practical benefit here? > > As I said later in the message to which you are replying, I don't agree > that redispatching implies a type inconsistency. > > Do you use the word "erroneous" in the formal Ada sense, "erroneous > execution"? Then could you please explain what kind of erroneous > execution redispatching can cause, that cannot occur without using > redispatching? As far as I understand, redispatching itself is safe; > erroneous execution can only come from code in the operations that are > invoked. It was merely a counterexample to "benefit" over "formalism". "Benefit" is bounded by "formalism", not otherwise. If we consider re-dispatch doubtful for formal reasons, that overrides any benefits (or we change the formalism). > If your argument is just that a program with redispatching is more > complex and thus more likely to contain programming errors, I partly > agree; redispatching makes the sequence of invoked operations more > dynamic and thus possibly harder to grasp and make correct. But this > argument applies as well to any kind of run-time dispatching, not just > to *re*-dispatching. I disagree. Dispatching does not make it more complex assuming that all implementations of the primitive operation are conform the interface. You write the client program in terms of another type, of the type T'Class. There is nothing automatically more complex in T'Class than in T. >> Your initial example was about certain decomposition of operations into >> class-wide and primitive, so that a primitive operation would call to >> class-wide ones. > > No, I think you mistunderstood my example, perhaps because I did not > explain it clearly enough. The two operations in my example are both > primitive, and can be independently overridden with behaviour suitable > to derived types. The operations call each other with redispatching to > activate the most suitable behaviour of each operation for the actual > type of object. Yes, I understand this. The question is why it was decomposed in this way. If one operation of the type T calls another operation of the same type. Why should it dispatch. When you call an operation of the type S on T, that is a type error to me. You have circumvented the type system, by an explicit type conversion of T to T'Class. Do not we agree that type conversions should be avoided? >> My point that such cases should be attributed to poor >> design > > In the mind of the beholder, I think. You haven't shown *why* this > design is "poor", except by your own design rules. I think I did. Why do you dispatch again, you already checked the tag. The type is determined, the reader expects the code to correspond that type, you break this convention. My concern is the semantics of the code. Semantically a primitive operation has separate bodies for each type in the class. This gets broken in your design. I.e. it is a third way of how bodies are decomposed. I may agree that the language could offer more than one body per class (class-wide) vs. one body per type (primitive). But so far, a design should conform to the existing model. >> There are also practical arguments that dispatching calls >> are slower, > > I don't expect to get something for free. Dispatching calls are slower > than statically bound calls, right? But you still use dispatching calls > when needed, right? Yes, but only if I cannot statically specify the type. Re-dispatch happens at the places where I already determined the type, but for some reasons am not satisfied with the outcome. Why? Strange... >> that re-dispatch requires referential semantics, > > I don't see why, Because of the type tag. You need same representation for T and T'Class to have T -> T'Class as a view conversion. > but I don't really care, as I have accepted (albeit > reluctantly) that I need referential semantics anyway. But it means that the design relies on referential semantics and cannot be rewritten in terms of value semantics. Formally there should be something fundamentally wrong with that, because there is no reason beyond 1. optimization issues, 2. outer world communication, why referential semantics is chosen. Yet we rely on it. Why? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de