Reflection?

Jonathan M Davis jmdavisProg at gmx.com
Mon Oct 25 15:20:39 PDT 2010


On Monday, October 25, 2010 11:55:53 Sclytrack wrote:
> == Quote from Jonathan M Davis (jmdavisProg at gmx.com)'s article
> 
> > On Sunday 24 October 2010 12:17:47 Sclytrack wrote:
> > > Instead of targeting doc files, could dmd create xml files
> > > for the purpose of runtime reflection, instead of trying to
> > > go to runtime reflection via __traits.
> > > 
> > > You can archive these files together with the binary code.
> > > Create some sort of D package.
> > > 
> > > I mean C (GNOME) is going with xml files for their introspection.
> > > http://library.gnome.org/devel/gi/unstable/gi-gir-reference.html
> > 
> > __traits isn't runtime reflection. It's compile time reflection. It's
> > highly useful in creating templates and string mixins and the like.
> > If you want runtime reflection, it's possible to use __traits to put
> > together a set of functions which hold the traits information to be
> > queried at runtime, thereby creating your own runtime reflection
> > mechanism (I think that someone around here has a project which does
> > exactly that actually), but there is no runtime reflection built into D.
> > If you wanted to, you could write code which would produce xml files that
> > held type information which could be read at runtime, but again, since
> > there is no runtime reflection in D, you'd have to do it yourself. Not
> > to mention, reading XML is not exactly very efficient given that you'd
> > be both reading a file and having to deal with parsing text, so I don't
> > know why you'd generally want to use XML to hold type information. XML
> > has its uses, but usually I'd think that you'd want runtime reflection
> > to be efficient, and XML isn't going to do that. - Jonathan M Davis
> 
>  Maybe the xml data could be converted to some
>  faster loadable format by a tool external to the compiler.
> 
> 
> D---->xml---->runtime reflection library
> D---->xml---->[binary files---->runtime reflection library]
> D---->xml---->More D code.
> 
> C---->xml---->Wrappers in other languages.
> C---->xml---->D binding code.
> 
> D------__traits()---->More D Code

But why would you _want_ the xml? The ideal situation would be something similar 
to Java where there are functions which you can call at runtime to inquire about 
an object. D has that for compile time but not runtime. So, you can use the 
compile time reflection to generate functions which do it at runtime. It's just 
not built in or standard. But xml?  What do you possiblly gain by having xml?

It makes no sense to me to try and use runtime reflection for language bindings, 
and you'd likely use C to interface with other languages if D can't interface 
with them directly. I just don't see why you would want a runtime reflection 
mechanism which was language agnostic, and there's no way that it would be an 
improvement for D to use xml to talk to D.

- Jonathan M Davis


More information about the Digitalmars-d mailing list