Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers > Re: Optimizatio...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 7 Topic 2408 of 2421
Post > Topic >>

Re: Optimization for OOP

by "Dmitry A. Kazakov" <mailbox@[EMAIL PROTECTED] > May 6, 2008 at 09:35 AM

On Mon, 5 May 2008 18:51:58 -0700 (PDT), lucretia9@[EMAIL PROTECTED]
 wrote:

> On 5 May, 17:37, "Dmitry A. Kazakov" <mail...@[EMAIL PROTECTED]
>
> 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




 7 Posts in Topic:
Optimization for OOP
sgkelly4@[EMAIL PROTECTED  2008-05-03 17:53:05 
Re: Optimization for OOP
torbenm@[EMAIL PROTECTED]  2008-05-05 09:45:24 
Re: Optimization for OOP
"Dmitry A. Kazakov&q  2008-05-05 18:37:26 
Re: Optimization for OOP
"lucretia9@[EMAIL PR  2008-05-05 18:51:58 
Re: Optimization for OOP
"Dmitry A. Kazakov&q  2008-05-06 09:35:25 
Re: Optimization for OOP
sgkelly4@[EMAIL PROTECTED  2008-05-06 23:13:32 
Re: Optimization for OOP
Tony Finch <dot@[EMAIL  2008-05-05 18:11:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 1:04:31 CDT 2008.