From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Avoiding dispatching in procedure's with classwide types
Date: Tue, 7 Jun 2016 09:43:54 +0200
Date: 2016-06-07T09:43:54+02:00 [thread overview]
Message-ID: <nj5u0u$1cb3$1@gioia.aioe.org> (raw)
In-Reply-To: 7263ac4b-945c-4702-b998-e87c1de1f4a7@googlegroups.com
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
next prev parent reply other threads:[~2016-06-07 7:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-28 19:01 Avoiding dispatching in procedure's with classwide types Jeremiah
2016-06-06 3:12 ` rieachus
2016-06-07 2:23 ` Jeremiah
2016-06-07 7:43 ` Dmitry A. Kazakov [this message]
2016-06-07 11:30 ` Jeremiah
2016-06-07 21:05 ` Randy Brukardt
2016-06-09 1:12 ` Jeremiah
2016-06-06 3:24 ` rieachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox