Proposal: Replace __traits and is(typeof(XXX)) with a 'magic namespace'.
Bill Baxter
wbaxter at gmail.com
Tue Nov 3 15:44:13 PST 2009
On Tue, Nov 3, 2009 at 1:27 PM, Derek Parnell <derek at psych.ward> wrote:
> On Mon, 02 Nov 2009 17:47:53 +0100, Don wrote:
>
>
>> 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>).
>
> Thank you Don for this "voice of reason". A specific keyword for the
> concept of compile-time activity/functionality is totally justified.
>
> "meta" is very suitable. Short and to the point.
Shortness is key. In compile-time code this keyword is going to
appear a lot. So if it's going to be a new keyword, I vote for this
one.
>
> "compiler" I could live with.
>
> "traits" is unsuitable, as it is too limiting a concept.
>
> "scope" is unsuitable, as it is already too highly overloaded with
> semantics.
>
> "static" is extremely unsuitable. This word should, at best, be only used
> for things that do not change value or location during run-time.
A type doesn't change whether it "isArithmetic" at runtime. A "static
if" doesn't change the branch it takes at run-time. So by your
explanation static is exactly the right thing to use.
> ... and slightly off topic ...
> now if only we could get the 'bang' out of template instantiation syntax as
> well. When I see the '!' in something like "Foo!(X)()", my mind first says
> "we are about to negate something" and then has to switch tracks "oh no,
> this actually means we are using a template this time".
It does make template code in D look noisy, but I don't think there's
much chance it's going away. I think if I were making a new language,
I'd seriously consider going with () for both indexing and function
calls, and use [] for template arguments.
--bb
More information about the Digitalmars-d
mailing list