Newbie initial comments on D language - RTTI and run-time reflection

Edward Diener eddielee_no_spam_here at tropicsoft.com
Wed Jan 30 17:11:52 PST 2008


Robert Fraser wrote:
> Edward Diener wrote:
>> Robert Fraser wrote:
>>> Edward Diener wrote:
>>>> But that is still only half the story. Run-time reflection in a RAD 
>>>> environment needs the ability to be able to create an object 
>>>> directly from the type of that object, and the type of an object 
>>>> must itself be instantiable as an object. This final ability is in 
>>>> Java, Python, .Net, and C++ Builder/Delphi. I can only encourage D 
>>>> to have this ability also.
>>>
>>>  From http://www.digitalmars.com/d/2.0/abi.html :
>>>
>>> The class definition:
>>>
>>> class XXXX
>>> {
>>>     ....
>>> };
>>>
>>> Generates the following:
>>>
>>>     * An instance of Class called ClassXXXX.
>>> [...]
>>>
>>> And from http://www.digitalmars.com/d/2.0/phobos/object.html :
>>>
>>> class ClassInfo;
>>>     Runtime type information about a class. Can be retrieved for any 
>>> class type or instance by using the .classinfo property. A pointer to 
>>> this appears as the first entry in the class's vtbl[].
>>>
>>>     byte[] init;
>>>         class static initializer (init.length gives size in bytes of 
>>> class)
>>>
>>>     string name;
>>>         class name
>>>
>>>     void*[] vtbl;
>>>         virtual function pointer table
>>>
>>>     Interface[] interfaces;
>>>         interfaces this class implements
>>>
>>>     ClassInfo base;
>>>         base class
>>>
>>>     static ClassInfo find(string classname);
>>>         Search all modules for ClassInfo corresponding to classname.
>>>
>>>         Returns:
>>>         null if not found
>>>
>>>     Object create();
>>>         Create instance of Object represented by 'this'.
>>>
>>>     const(MemberInfo[]) getMembers(string name);
>>>         Search for all members with the name 'name'. If name[] is 
>>> null, return all members.
>>
>> That is start, but it looks like I will wait for 2.0 to be done before 
>> I investigate further.
>>
>> BTW I do realize what a major effort it is to provide metaclass 
>> information such as ClassInfo and further facilities so that full 
>> run-time reflection can be done. I would not be disappointed if D did 
>> not fully offer such facilities, but my argument here is not that I do 
>> not understand the huge effort but that once D offers that sort of 
>> facility it becomes possible do to some amazing thing with it and 
>> would be worth it.
> 
> That's in D1, too.

It may be in D1, but if it is undocumented it is doing no one any good.



More information about the Digitalmars-d mailing list