Proposal: Definition of @-attributes

Leandro Lucarella llucax at gmail.com
Thu Jan 28 05:45:35 PST 2010


Lars T. Kyllingstad, el 28 de enero a las 09:46 me escribiste:
> In the "Function calls" thread the question of "which attributes
> should be in the @-namespace" has again come up.
> 
> Problem:
> Currently, there doesn't seem to be any clear definition of which
> attributes should be prefixed with @ and which shouldn't.  New
> attributes get an @, while already existing attributes don't, and it
> all seems a bit arbitrary.  Then again, we probably don't want *all*
> attributes to be written with @, as that would just make code look
> messy:
> 
>     @safe @nothrow @private @property int foo() { ... }
> 
> 
> Solution (?):
> I therefore propose the following definition of @-namespace attributes:
> 
>     The @-attributes of a function only place compile-time
>     constraints on the body of that function.
> 
> Specifically, this means that the @-attributes of a function do not
> place constraints on calling code, change the syntax of calling
> code, nor change the visibility of the function.
> 
> The above definition means that the following will be @-attributes:
> 
>     @safe, @trusted, @unsafe
>     @nothrow, @pure
> 
> The following, on the other hand, will be normal keywords:
> 
>     private, protected, public
>     deprecated, disable
>     property
> 
> I realise that a major problem with the proposal is that it severely
> limits the possibility of later having user-defined annotations in
> the @-namespace as well.  But I am not convinced this is a good idea
> anyway.

It is! Even more, a big reason for introducing @attributes was to be able
to make them user-defined.

I don't like your proposal mostly because of this point (but because is as
arbitrary as the current regime, it only adds a mnemonic rule to remember
where to put the @).

I think all D attributes should have the @, if you have a bunch of them,
maybe there should be a way to group them, like:

     @(safe nothrow private property) int foo() { ... }

But I'm not sure that adds anything to readability. I don't think this is
a huge problem, since as somebody already pointed out, you can always
group declarations with the same attributes together and type the
attribute just once (this is not Java :).

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------



More information about the Digitalmars-d mailing list