Reflection Idea

Josh Stern josh_usenet at phadd.net
Tue Sep 26 23:25:21 PDT 2006


On Thu, 14 Sep 2006 18:32:05 -0400, Pragma wrote:

> Craig Black wrote:
>> Since DDL provides run-time reflection, and is finally ready to use, I 
>> thought it would be a good time to share my idea to improve performance when 
>> accessing metadata.

>> However, we could get the metadata more quickly if it was available via the 
>> TypeInfo class.  This could be made possible very easily if the TypeInfo 
>> class contained a reference to an IReflection interface.  This reference 
>> could be set by the reflection database at program startup.  This would 
>> provide a direct link to meta data for each class, and would make reflection 
>> a first class citizen in D.
> 
> The only reason why I'd consider full-on reflection for D a bad move is 
> that it'll bloat program sizes considerably.  This is kind of contrary 
> to D's goal as a systems programming language.  Taking into 
> consideration the sheer size of your average .map file is a good 
> indicator of just how bad things can get.

Different people undoubtably have contrasting ideas about what they'd
like to use reflection for.   In my mind, the most important application
of Java's reflection interface is the automation of object serialization.
Since I/O programming tends to be one of the most time consuming and
error-prone aspects of development, any sort of powerful automation
in this area is valuable.  I'm a newbie to D, but as far as I can tell
from the docs, the info to do something comparable isn't available in 
the binary files or the compile time interface.

> So I'd caution the addition of adding such a suite to D as something 
> optional if at all possible.  Even something minimalisitc would work - 
> like the inclusion of just a hashtable of all the program's symbols 
> (metadata as Craig put it above) that is *optionally* compiled in.

It could be supported without bloat by making the info either something
which is either statically accessed or else dynamically loaded from
a supplemental database file.  Opening up useful interfaces to the
language parser and using them  in separate tools (i.e. like Open C++)
is another possible approach to compile time reflection.








More information about the Digitalmars-d mailing list