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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.110.81 with SMTP id w78mr1253730itc.8.1465299003443; Tue, 07 Jun 2016 04:30:03 -0700 (PDT) X-Received: by 10.157.4.36 with SMTP id 33mr241829otc.15.1465299003299; Tue, 07 Jun 2016 04:30:03 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!q32no4741996qgq.0!news-out.google.com!z5ni71qge.0!nntp.google.com!q32no4741945qgq.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 7 Jun 2016 04:30:03 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.171.109.232; posting-account=vk6_JwoAAABkMyHO1YfdP69Hm3CpbdGR NNTP-Posting-Host: 71.171.109.232 References: <8af002bb-271a-4a76-b0db-097a3724f0b3@googlegroups.com> <7263ac4b-945c-4702-b998-e87c1de1f4a7@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Avoiding dispatching in procedure's with classwide types From: Jeremiah Injection-Date: Tue, 07 Jun 2016 11:30:03 +0000 Content-Type: text/plain; charset=UTF-8 Xref: news.eternal-september.org comp.lang.ada:30646 Date: 2016-06-07T04:30:03-07:00 List-Id: On Tuesday, June 7, 2016 at 3:44:33 AM UTC-4, Dmitry A. Kazakov wrote: > On 07/06/2016 04:23, Jeremiah wrote: > > > So my question is if the method used in Copy_Value_1 considered a > > no-no or since it bypasses dispatching in favor of directly copying the > > values in a procedure that takes a class wide type? Or is it ok since > > there is no guarantee to what the internals of the Copy_Value_1 > > procedure are? My gut is it is bad form, but I wanted to know if I was > > just over thinking it. > > The answer depends in your example on whether it represents a full > multiple dispatch or not. Assignment is multiple dispatch by definition. > So the implementation you presented is in general wrong. But, *IF* one > of the types involved is final and does not have any descendants the > implementation is OK. > > In the declarations provided, both types are tagged and thus there is no > hint that one of them were final. Therefore in order to make it right > one of the types must be made, at least, publicly untagged. > > There is an Ada design flaw that privately tagged types easily leak into > public declarations, so, possibly, the tagged type should be wrapped > into a non-tagged record. > > > As for why I would think it would improve performance: > > No. Multiple dispatch should be far faster that its cascaded poor-man's > emulation through single dispatches, in case it is really a multiple > dispatch. > > > GNAT doesn't > > tend to optimize out dispatching calls > > There is no need to "optimize" them. The design of dispatch in Ada is > such that when you could optimize it, there should be a specific type > already and the call non-dispatching. All "optimization" is already > here, static on the language level. Anything else, e.g. re-dispatch > cases are software design bugs, IMO. > > > But it might also leave the procedure > > open to bugs on derived children? > > If you violate typing then yes. Assignment is an MD operation. Its > implementation as a non-MD operation violates typing and thus is open to > any bugs. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de Thanks! That was my feeling. I'll probably go back and make the types final then. Kinda sucks because I like the dot notation for function calling. I wonder why they chose to make the dot notation require a tagged type?