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

Edward Diener eddielee_no_spam_here at tropicsoft.com
Mon Jan 28 20:35:24 PST 2008


Jarrett Billingsley wrote:
> "Edward Diener" <eddielee_no_spam_here at tropicsoft.com> wrote in message 
> news:fnm1qm$1tiu$1 at digitalmars.com...
>> 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.
> 
> There is flectioned (http://flectioned.kuehne.cn/), likely the library you 
> mentioned.  The D compiler by default inserts some RTTI information, but 
> it's not complete by any means.

Yes, that is the library but I have not looked at it yet myself. Because 
it mentioned reflection, I assumed that run-time reflection must be 
available in D in some form.

> 
> The nice thing about compile-time reflection, though, is that you can use it 
> to _create_ runtime reflection from within the language, rather than relying 
> on a third-party tool to do so.  This offers the possibility of providing 
> runtime reflection, which is a feature not everyone needs, as part of the 
> standard library rather than as a built-in feature of the language. 

 From the facilities mentioned at 
http://digitalmars.com/d/2.0/traits.html it is hard to imagine how one 
can create runtime reflection on unknown types at compile time. If it 
can indeed be done then it appears to be something that can not be done 
from the outside by a 3rd party tool since that tool would have to be 
able to be compiled and know about partcular types in advance in order 
to gather the data it needs. There is no use in the link above for using 
strings to pass the names of the types that one needs to reflect. So I 
have to believe there is more to it than the link above explains.

Real run-time reflection in D would mean that:

1) One can query for the names of all types in a module given a module name.
2) One can query for all parts of a type given a type name or an object 
of that type.
3) One can instantiate a type given a type name and exercise that type 
by calling its methods, getting and setting its properties, triggering 
its events etc.

I think you get the idea.

I could go into the major usage of run-time reflection in modern IDE 
environments but if I just say RAD programming, ala forms, components, 
and design-time manipulation as in C++ Builder and later in Visual 
Studio .Net, you can probably extrapolate where I am going with it. I 
will just add that C++ as a a standard has been adamantly opposed to 
such ideas, but from this programmer's point of view it will be the way 
of programming in the future. Without real run-time reflection RAD 
programming is nearly hopeless. That is the reason why implementing it 
in D and working toward a RAD programming IDE using D would be a major 
advantage and selling to using D over and above its additions and 
possible improvements to C++ IMO. But I do realize how difficult adding 
run-time reflection may be from the compiler's point of view.



More information about the Digitalmars-d mailing list