Annotations for D
Yigal Chripun
yigal100 at gmail.com
Fri Apr 25 06:48:45 PDT 2008
I've posted several times my opinion that D needs an annotation
mechanism like .net/java provides.
here's my initial idea (please help beat out all the bugs and such):
definition of such an attribute would be similar to writing a class or
interface only it will denoted by the keyword "attribute":
public attribute attr1 {
...implementation code ...
}
and would be applied as:
[attr1, attr2("val1", 123)]
int func(int a, int b);
assume the above attr1 and attr2 are attributes, where the constructor
of attr2 receives (string, int) as parameters.
the attributes are defined in an attribute array, so in generic code
it'll be possible to do things like attributes["attr2"] to get the
values of that attribute.
in order to implement attributes, the D specification should have a
"System" package or something similar that would provide an API to the
compiler. this package would provide a method for the above attributes
array, for example.
Note: this is just an initial bud of an idea, but we really do need to
start thinking in this direction if we want D to have an intuitive
syntax in the future. see my reply to Walter in the "what is nothrow
for?" thread.
Walter, you are a genius compiler writer, please don't over complicated
D2 syntax, and consider the above suggestion.
The above would help both the D language itself and the library writers
would would use such a feature extensively (as we can see in .net/Java
today - both used a lot in the industry). That would bring us one step
closer to the adoption of D in the industry.
--Yigal
More information about the Digitalmars-d
mailing list