Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'.
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Mon Nov 2 09:05:00 PST 2009
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>). This would give us:
>
> meta.compiles(XXX)
> meta.isArithmetic; // note, property syntax OK if no arguments
> meta.isArithmetic(int*);
>
> Benefits:
> * Fewer keywords: __traits -> meta, typeid() -> meta.typeid()
> * Get rid of is() expressions, which are the most complicated thing in
> the language.
> * Some meta.XXX functions could be defined in runtime library code.
> * The existing __traits functions could have more useful return values.
> * Retain the flexibility of __traits.
>
> These days, I don't propose anything unless I'm prepared to write a
> patch to implement it. <g>
>
> If nothing is, this should convince everyone that there's NO REASON to
> put up with the ugly metaprogramming syntax we currently have. We can do
> much better. Easily.
I'm all for it. I vote for 'meta'. :)
-Lars
More information about the Digitalmars-d
mailing list