<div class="gmail_quote">On 16 March 2012 15:35, Adam D. Ruppe <span dir="ltr"><<a href="mailto:destructionator@gmail.com">destructionator@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
@note(Serializable.yes) int a;<br></blockquote><div><br></div><div>Surely the term you're looking for here is @annotate(...) ?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This simple extension to the language enables libraries,<br>
using existing traits to navigate symbols, to get<br>
additional information about things and implement it<br>
however.<br>
<br>
The lack of user defined attributes is D's biggest missed<br>
opportunity right now, and I think this simple proposal<br>
will plug that hole.<br></blockquote><div><br></div><div>I agree it's a very big hole against popular competing languages (Java, C#).</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Previous user-defined attribute proposals have had counter<br>
arguments like these:<br>
<br>
1) how do you define what is and is not a valid attribute?<br>
<br>
Here, the answer is pretty simple: you can put whatever notes<br>
you want on the thing. Whether the library uses it or not<br>
is up to it.<br></blockquote><div><br></div><div>What if you want to annotate with a variable? Each instance may need to hold some attribute state. This is extremely common, particularly in serialisation systems which typically perform lazy updates, and need some additional state for that.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">2) OK, how do you namespace things so different libraries don't<br>
get different results?<br></blockquote><div><br></div><div>Surely this is just as easy: @modulename.attribute int myThing;</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am I missing anything?<br></blockquote><div><br></div><div> I think it only solves half the problem. There are certainly cases where you just want to annotate with some sort of tag, so you can know to do something special in this thing's case, but there are also times where you want to associate some variable data with each instance.</div>
<div><br></div><div>Perhaps that's the key distinction between 'annotation' and a 'custom attributes' .. an annotation this way is a shared compile time constant, associating with its type info, as you suggest. A custom attribute is an instance-specific association vontaining variable data.</div>
<div>I'd suggest that @annotate(someEnum) could work effectively just as you suggest, but it doesn't fill the requirement for custom attributes, which could be implemented separately, something like:</div><div><br>
</div><div>attribute myAttribute<br></div><div>{</div><div>  this(int something);</div><div><br></div><div>  bool bNeedsAttention;</div><div><br></div><div>  property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; }</div>
<div>}</div><div><br></div><div><div>@myAttribute(10) int thing;<br></div><div><br></div>thing.refresh = true;</div></div>