Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'.

dsimcha dsimcha at yahoo.com
Mon Nov 2 12:37:23 PST 2009


== Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
> Don wrote:
> > Andrei Alexandrescu wrote:
> >> Don wrote:
> >>> [I'm moving this from deep inside a TDPL thread, since I think it's
> >>> important]
> >>>
> >>> is(typeof(XXX)) is infamously ugly and unintuitive
> >>> __traits(compiles, XXX) is more comprehensible, but just as ugly.
> >>>
> >>> They are giving metaprogramming in D a bad name. I think we need to
> >>> get rid of both of them.
> >>>
> >>> A very easy way of doing this is to replace them with a 'magic
> >>> namespace' -- so that they _look_ as though they're functions in a
> >>> normal module.
> >>> Names which have been suggested include 'meta', 'traits', 'scope',
> >>> 'compiler'. Personally I think 'meta' is the nicest (and I suggested
> >>> two of the others <g>).
> >>
> >> Another keyword, sigh...
> >>
> >> And I'll be darned if "static" isn't the perfect fit :o).
> >
> > I suggested 'scope', as well, if you need to minimize keywords.
> > You can get rid of typeid, though, which is a real keyword, by moving it
> > to the same namespace.
> Well ok. Anyhow, something we need to integrate: one problem with typeid
> is that it should return the dynamic type for class objects. For
> example, typeid(this) in an abstract class or an interface should return
> the TypeInfo for the derived class. I was majorly surprised that that's
> not the case at all.

Isn't that what this.classinfo is for?

> Walter acknowledged that he's given a few tries at
> providing decent run-time reflection hooks (typeid, classinfo) but none
> really work. He agreed that the entire mechanism is due for a thorough
> review.

I think the solution is for classinfo and typeinfo to be templates.  I mentioned
that here a few days ago, but it was admittedly poorly written, with tons of
references to GC hacks.  I'll write a clearer proposal tonight.  The idea is that,
if typeinfo and classinfo were templated on the type that they were providing
information about, it would be very easy for anyone to add more information to
them--anything that is available at compile time would be available in RTTI with
trivial modifications to object.d.



More information about the Digitalmars-d mailing list