So, User-Defined Attributes

Era Scarecrow rtcvb32 at yahoo.com
Sun Jan 6 07:56:47 PST 2013


On Saturday, 5 January 2013 at 11:57:39 UTC, Johannes Pfau wrote:
> Era Scarecrow wrote:
>> This is sorta like tuples; But from the brief summaries I 
>> cannot fully understand how or where they would be used. I 
>> understand some attributes can be made and added that some 
>> compilers may use (@noreturn as an example), but outside of 
>> the compiler I'd need an example of how to make use of them.
>
> One example is std.benchmark. It currently detects if a 
> function is a benchmark function by checking the name: void 
> benchmark_stdio();
>
> With UDAs we can do this:
> @benchmark stdio();
> or
> @benchmark("Benchmarking stdio reads, using xKB buffer") 
> benchStdio1();
>
> There's still the issue of "How do I get all the declarations 
> in a module (/ the applications)", but UDAs already help a lot.

  Yes I understand how you can attach some information using a 
UDA, but that still doesn't tell me _how to use_ it. Unless you 
can somehow locate & manipulate/use/pass the information around 
than it's no more than a comment that isn't removed immediately.


  Slightly off topic: I get the feeling that with the questions of 
current specs, the large number of changes (few hugely breaking) 
and outdated TDPL the language documentation needs a good through 
update. Perhaps a TDPL v2 regarding changes to the language; 
Rather than replacing TDPL, it instead it compliments it. And 
when phobos is more mature and isn't going to be changing then an 
API/reference book for it would likely be a third book.


More information about the Digitalmars-d mailing list