Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'.
Steven Schveighoffer
schveiguy at yahoo.com
Mon Nov 2 11:35:19 PST 2009
On Mon, 02 Nov 2009 11:47:53 -0500, Don <nospam at nospam.com> 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.
>
According to Andrei's reply, __traits is not a keyword (or at least does
not have the downside of using a likely variable name) since __ symbols
are reserved, so your assertion that less keywords isn't technically
correct. But IMO, something this important deserves a keyword, and I
*hate* the less keywords is unequivocally better POV. Also, I was under
the impression that __traits was a placeholder until both 1) __traits
proved to be a useful feature (and it has) and 2) a good name could be
found, is this not the case?
I'm not sure you need to get ride of typeid. The benefits to deprecating
a keyword don't seem very apparent to me, you still most likely need to
keep the keyword for backwards compatibility.
I agree with you on is() expressions, but you need to replace them all,
not just the is(typeof(XXX)) form.
And I agree with you on the whole. I'd say the best thing to do is
implement the feature (it seems you have a good grasp on what needs to be
done) and take a particularly nasty __traits-using module, and show how it
looks with the new style :) Hell, even doing the second part may be
enough to convince Andrei/Walter.
vote++
-Steve
More information about the Digitalmars-d
mailing list