Reflection Idea
Pragma
ericanderton at yahoo.removeme.com
Wed Sep 27 11:50:38 PDT 2006
Josh Stern wrote:
> 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.
I agree with you completely, Josh. D really needs both a runtime and a
compile-time reflection facility to suit all modes of use. On the
compile-time side, there have been some rather amazing efforts to use
templates to provide traits and other info - but there's obviously some
stuff missing from TypeInfo.
>
>> 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.
FWIW, I have the "dynamically loaded from a supplemental database file"
part done. DDL just uses the map file:
http://www.dsource.org/projects/ddl/wiki/Tutorial/UsingDDL/Reflect
//reflect.d
module reflect;
import ddl.DefaultRegistry;
import mango.io.Stdout;
void test(){
Stdout.put("Hello DDL World"c).put(CR);
}
void main(){
auto registry = new DefaultRegistry();
auto inSitu = registry.load("reflect.map");
auto testFn = inSitu.getDExport!(void function(),"reflect.test")();
testFn();
}
It's not as pretty as Java's reflection suite, but IMO, it's only a few
wrapper classes away from that level of utility.
--
- EricAnderton at yahoo
More information about the Digitalmars-d
mailing list