Reflection Idea

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Sep 22 14:10:48 PDT 2006


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.
> 
> Technically DDL does, although I'm hesitant to call it that since it 
> doesn't have all the typical reflection bells-and-whistles yet.
> 
>>
>> If we have an instance of a class and we want to it's metadata via a 
>> reflection database, we should be able to query the reflection 
>> database using a hash table lookup on the name of the class.
>>
>> 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.
> 
> 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.
> 
> Otherwise, we're stuck with .map/.situ support under DDL - i.e. using 
> your .map file as a runtime dependency for the program.  While this 
> works well, and is such a dead-simple way of addressing the problem, 
> it's also easy to get out of sync IMO.
> 
> [PSA]
> 
> Craig, if you're at all interested in hammering out a reflection 
> interface (for DDL?), the DDL Community wiki there is open for your, and 
> everyone else's abuse.
> 
> http://www.dsource.org/projects/ddl/wiki/Community
> 
> I have some reflection concepts, and a few other ideas, outlined under 
> the DevNotes section as well:
> 
> http://www.dsource.org/projects/ddl/wiki/DevNotes
> 
> Enjoy!
> 

Hum, it may be the case for runtime reflection, but as for compile-time 
reflection, it would have quite a lot of usefulness, and no 
performance(or other kind of) drawbacks of merely being available.
I'm not saying this about compile time reflection in the sense that it 
would serve as substitute to runtime reflection, it wouldn't. At least 
not in a complete, for-all-cases sense. I think both kinds have some 
uses that cannot be covered by the other kind.


-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list