On 2012-09-19 01:21, Rob T wrote:
Actually I find the __traits system a bit convoluted and inconsistent
with other similar features. There seems to be a real need to unify the
different methods of reflection in D.
For example, I can do this without using __traits
int i;
writeln( i.stringof );
and I can do this
void function x() {};
writeln( x.stringof );
but it won't work for the main function
int main(char[][] args)
{
writeln( main.stringof ); // compile error (bug?)
}
I think the reason for this is that the compiler will resolve "main" as
a function call, but it will fail because no arguments are given. This
is a typical feature where it seems no one really know how it should
behave. .stringof is very poorly documented. It says nothing about what
the returned string might look like.
but this works
writeln(__traits( identifier, main ));
It seems that __traits(itentifier, ) and .stringof are two ways of
getting access to the same information.
So why do we have __traits and the built in properties that overlap in
functionality? Why is it inconsistently applied as seen with function
main (although that could simply be a bug)? The situation is rather
confusing.
.stringof was available long before D2 was created, __traits is only
available in D2. I think __traits was create to try to improve the
compile time reflection abilities in D.
--
/Jacob Carlborg