POV-Ray : Newsgroups : povray.off-topic : Generics annoyance : Re: Generics annoyance Server Time
4 Sep 2024 15:17:26 EDT (-0400)
  Re: Generics annoyance  
From: Warp
Date: 14 Apr 2010 15:37:30
Message: <4bc6197a@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> For something managed, I think that would be the wrong way to implement MI. 
> It's still just one object, even if it inherits data and code from multiple 
> classes.  For example, Python has MI and doesn't have pointers into the 
> middle of objects.

  That sounds like it would be somewhat inefficient. If the pointer always
points to the beginning of the object, then it would always need to resolve
the offset to the members it wants every time it wants to access them
(because in a multiple-inherited object the members of the base class you
want do not necessarily start from the beginning of the object the pointer
is pointing to, but could start from anywhere).

> You could also do it as a sort of "automatic delegation", where each of the 
> multiple parent classes is represented as a separate object on the heap, for 
> example, and the child class delegates all the non-overridden calls to the 
> parent class.

  That sounds like you would need several steps of indirection in order
to access a base class member using a derived class pointer. And checks
for this would need to be done for *all* accesses, even in situations where
there's no inheritance at all (because the code which tries to access the
object through the pointer cannot know if the object it was given was a
derived object or not, without always checking).

> The only reason C++ carries pointers to the middle of objects (as far as I 
> can tell) is that they can't rewrite the object code to use different 
> offsets in the child class compared to the parent class, and of course 
> because it can since there's no memory compaction.

  It's more efficient when code which handles objects of a certain type
doesn't need to perform any checks to see if the object is really of that
precise type, or whether it's some inherited type. From the point of view
of that code the object looks exactly like if it was exactly of that
precise type (all the member offsets are always the same) regardless of
what the actual type of the object is.

  (Things like virtual inheritance can complicate this a bit, though.)

> Probably right after the folks working on Java do. ;-)

  Well, the Java people added their crippled version of templates to the
language regardless of all the arguments why templates are bad, so maybe
there's hope that MI will also be added, regardless of all the arguments
why it's bad.

  (It has always amused me how in the dawn of Java people constantly
preached how Java was like "C++ done right", yet it seems to lack most
things which are *good* and/or useful in C++, like RAII, destructors,
typedefs, enums, templates, multiple inheritance, handling objects by
value, operator overloading and whatnot.)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.