Custom attributes (again)

Kapps opantm2+spam at gmail.com
Thu Apr 5 15:17:14 PDT 2012


On Thursday, 5 April 2012 at 17:36:31 UTC, Walter Bright wrote:
> On 4/5/2012 5:00 AM, Manu wrote:
>> C# and Java both have attributes, following these established 
>> design patterns, I
>> don't think there should be any mystery over how they should 
>> be implemented.
>
> At the Lang.NEXT conference over the last 3 days, I was able to 
> talk to many smart people about attributes. But I did find some 
> confusion - are they best attached to the variable/function 
> (i.e. "storage class"), or attached to the type ("type 
> constructor")? I think the former. Attaching it to the type 
> leads to all sorts of semantic issues.
>
> From your list of uses, it looks like attaching it to the 
> variable or function is an apropos solution.

I'm not sure if I'm understanding this correctly, but by 
attaching to the type do you mean altering the type of the 
declaration such as shared or const do? If so, I am completely 
against attributes being able to do this; there's already better 
ways such as a struct with alias this. Another issue is that if 
runtime reflection gets added, it would be nice to be able to add 
attributes at runtime. This could cause things to break if the 
type itself is changed instead of getting attached to the 
declaration. Plus, attributes should not be invasive, they're 
just notes.

The two main situations where I see attributes being used are:
1) Add some information about a declaration, such as 
@NotSerialized on a field.
2) Add some information to a type, such as @Serializable.
If this can be done, with being able to pass compile-time 
value(s) to the attribute, all situations I have ever 
desired/seen/used attributes for would work nicely.


More information about the Digitalmars-d mailing list