Re: Optimization for OOP
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Tue, 6 May 2008 09:35:25 +0200
On Mon, 5 May 2008 18:51:58 -0700 (PDT), lucretia9@xxxxxxxxxxx wrote:
On 5 May, 17:37, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
wrote:
I think a consistent types system would be a better way. In Ada it
is always known if a call is dispatching or not. That is because of
proper typing. When an object is of a specific type, its methods
never dispatch, for that obvious reason, that the type is known to
be specific.
From what I've read about it, in Ada you can actually statically or
dynamically dispatch depending on *how* you call the subprogram. I've
not tried this BTW, but would love to see an example :D
Strictly speaking it does not depend on "how", it depends on "what", i.e.
on the object's type:
type T is tagged null record; -- a type
procedure Foo (X : T); -- a method of T
type S is new T with null record; -- a derived type
procedure Foo (X : S); -- Foo gets overridden for S
O1 : T; -- the type is specific T
O2 : S; -- the type is specific S
O3 : T'Class := O1; -- the type is unspecific, any derived from T
O4 : T'Class := O2; -- like above
Foo (O1); -- statically resolved to Foo of T
Foo (O2); -- statically resolved to Foo of S
Foo (O3); -- dispatches to Foo of T
Foo (O4); -- dispatches to Foo of S
O3 and O4 are polymorphic objects (Ada uses the term "class-wide"). IFF a
method (Ada calls it "primitive operation") of some type T is called on a
polymorphic object from the class of T, that dispatches according to the
type tag of the object.
The types of polymorphic and specific objects are different in Ada. They
are T'Class and T respectively. This eliminates re-dispatch in methods and,
though Ada does not go that far, potentially allows an implementation of
multiple dispatch, as well as classes of small scalar types with value
semantics, like Boolean and Integer (without space/performance overhead).
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.
- Follow-Ups:
- Re: Optimization for OOP
- From: sgkelly4
- Re: Optimization for OOP
- References:
- Optimization for OOP
- From: sgkelly4
- Re: Optimization for OOP
- From: Torben Ægidius Mogensen
- Re: Optimization for OOP
- From: Dmitry A. Kazakov
- Re: Optimization for OOP
- From: lucretia9@xxxxxxxxxxx
- Optimization for OOP
- Prev by Date: Re: Optimization for OOP
- Next by Date: Re: Compiler optimizations on GPU?
- Previous by thread: Re: Optimization for OOP
- Next by thread: Re: Optimization for OOP
- Index(es):
Relevant Pages
|
|