DIP6: Attributes

grauzone none at example.net
Mon Aug 3 09:29:17 PDT 2009


Max Samukha wrote:
> It would be nice (and that is unlikely to happen) if the compiler
> could rewrite
> 
> struct Foo
> {
>     @Persistent("db_field")
>     @Serializable
>     int field;
> }
> 
> to
> 
> struct Foo
> {
>     int field;
>     mixin Persistent!("field", "db_field");
>     mixin Serializable!("field");
> }
> 

It'd be even nicer if it wouldn't require ridiculous hacks from you to 
read out the annotation data again.

E.g. right now, that Serializable mixin would define something like 
"const bool field_serializeable = true;", and you'd need to use CTFE 
string concatenation (better hope the compiler's GC is enabled) and is() 
to define/read the data. Very clumsy and hackish, although it would work.

For me, making these things simpler is the whole point of annotations.

Looks like we have three basic things that annotations could be used for:
1. alternative namespace for keywords
2. associate arbitrary, user defined metadata with types and fields
3. macro madness (using the approach found in Python)



More information about the Digitalmars-d mailing list