User Defined Attributes (UDA) in Phobos/druntime

Idan Arye GenericNPC at gmail.com
Tue Jun 11 07:48:13 PDT 2013


On Tuesday, 11 June 2013 at 07:00:29 UTC, Jacob Carlborg wrote:
> The idea is to have a kind of meta UDA called "attribute". This 
> attribute needs to be attached to all structs, enums and so on 
> that is to be used as an attribute.
>
> The module provides a template (getAttributes) to get, by 
> default, only those values attached to a given symbol that is 
> an attribute. That is, marked with the "attribute" attribute.
>
> So my suggestion for guidelines are:
>
> * Only types with the "attribute" UDA is to be used as 
> attributes
> * In general, don't use primitive values as a UDA
>
> Don't use this
>
> @(3) int a;
>
> Use this:
>
> @attribute struct foo { int b; }
>
> @foo(3) int a;
>
> * A user defined type marked with "attribute" should not be 
> used for something else than an UDA
>
> * All attributes use camel case names

Camel case has two versions - and I suggest to use the one that 
starts with capital - that is, `@attribute struct FooBar` and not 
`@attribute struct fooBar`. This will save a lot of trouble when 
we want to add new keyword attributes.

The exception is the `attribute` attribute itself - in the future 
we might want to make it a keyword attribute(so we can, for 
example, enforce it's usage for attributes), and it that case it 
would be helpful if all UDAs already use it.


More information about the Digitalmars-d mailing list