Should pure nothrow ---> @pure @nothrow ?

Lutger lutger.blijdestijn at gmail.com
Sat Nov 28 02:05:19 PST 2009


Don wrote:

> Ary Borenszweig wrote:
>> Don wrote:
>>> #ponce wrote:
>>>>> Definitely. And what about @deprecated and @override?
>>>>
>>>> As override is now required, i don't think it should be an attribute.
>>>
>>> As I understand it, one of the characteristics of attributes is that
>>> you should be able to remove them from the entire program, without
>>> affecting the behaviour.
>> 
>> This is not correct. For example in C# you have the Flags attribute for
>> enums:
>> 
>> enum Foo {
>>   One = 1,
>>   Two = 2,
>>   Three = 4,
>> }
>> 
>> You can't do:
>> 
>> var x = Foo.One | Foo.Two;
>> 
>> but if you do:
>> 
>> [Flags]
>> enum Foo { ... }
>> 
>> you can do it now.
>> 
>> Also see this:
>> http://msdn.microsoft.com/en-us/library/system.flagsattribute(VS.71).aspx
>> 
>> Removing the Flags attribute changes program behaviour. An attribute,
>> indeed, tells someone (the compiler, the programmer, an external tool)
>> that a symbol has some attribute. It could change the program if the
>> compiler is the one using that attribute. So in theory every attribute
>> in D could be an @attribute.
> 
> Interesting. I think if we go to that extreme, the annotations would
> just end up being keywords, but slightly uglier.
> It seems clear that if @safe is an annotation, then @pure and @nothrow
> are, too.
> 
> I also think that the huge body of C++, Java, C# (and even D!) code sets
> a precedent that public, protected, extern, and private should not be
> annotations -- I'd suggest that if it is a keyword in C or C++, it
> should not be an annotation. (Although that would make align a keyword,
> not an annotation, though it'd otherwise be a candidate).
> 
> Beyond that, I'm not really sure. I'd tentatively go for @deprecated,
> and @property seems to have been decided, but for override -- no idea.
> 

In practice attributes in .NET are used for even more than that. A lot of 
API's seems to use them to provide features which could have been in code. 
Take nunit for example, it defines about 35 attributes to provide 
information about unittests. In a previous version this was done by naming 
convention and inheritance: 
http://www.nunit.org/index.php?p=attributes&r=2.5.2

I tend to think attributes in .NET are a regular means of abstraction, much 
like classes or generics. In part, they make up for lack of other 
metaprogramming features in some .NET languages.



More information about the Digitalmars-d mailing list