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

Edward Diener eddielee_no_spam_here at tropicsoft.com
Mon Jan 28 20:37:31 PST 2008


Christopher Wright wrote:
> Edward Diener wrote:
>> Xinok wrote:
>>> Edward Diener wrote:
>>>> I have searched through the pdf documentation bit did not find a full
>>>> explanation of RTTI facilities in D. The reason I ask about this is 
>>>> that
>>>> it appears there is a 3rd party reflection facility but I do not see 
>>>> the
>>>> documentation in D that explains if and how reflection works in D. Does
>>>> it exist in D ? Is there documentation for it ?
>>>>
>>> D 2.0 is an experimental branch which supports compile time 
>>> reflection. It's documented here:
>>> http://digitalmars.com/d/2.0/traits.html
>>
>> That is compile-time reflection, which is useful for creating code but 
>> not for instantiating objects at run-time and finding out about them. 
>> It is also very limiting in the form presented as one can not 
>> instantiate objects in the compile time constructs based on the 
>> information returned, but just react in a way to the information 
>> found. I am not putting down the effort as it more than duplicates and 
>> is more effective than the Boost traits library, since it is based on 
>> compiler knowledge.
>>
>> Is there any run-time reflection in D ? If not I would like to make a 
>> strong argument for it on this NG and then let others comment on it or 
>> at least have Walter see it. I realize implementing run-time 
>> reflection in any language is exceedingly difficult, but my argument 
>> would make a case for its importance in D if it could be done.
> 
> Runtime reflection is quite weak in D. I was considering providing some 
> facility for it for one of my projects, but that turned out not to be 
> necessary, so I decided against it.
> 
> The main problem is getting all types. You can easily register a type 
> for RTTI with a mixin, but I'm not sure how else to do it. I thought I 
> saw a trait to do it (__traits(derivedTypes, Object)), but I was 
> mistaken, and such a thing would be pretty much impossible. In my 
> situation, I didn't need nearly so much information; the trouble was 
> passing type information to arbitrary entities.
> 
> I browsed the Flectioned source once to see how it acquired runtime type 
> information, but it scared me, and I haven't looked at it since.

I will take a look at Flectioned and perhaps the things it can do will 
surprise me. But I have the sneaking suspicion that I am not cognizant 
of all there is to know about RTTI in D as yet.



More information about the Digitalmars-d mailing list