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.

I'd also suggest the convention that @-attributes are written after the function signature, while other attributes are written before:

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

Comments?

-Lars

Reply via email to