Why do some language-defined attributes have @ and some not?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Oct 24 17:45:14 PDT 2014


On Friday, October 24, 2014 23:38:38 Chris Williams via Digitalmars-d-learn 
wrote:
> On Thursday, 23 October 2014 at 07:39:21 UTC, Gary Willoughby
>
> wrote:
> > On Thursday, 23 October 2014 at 00:59:26 UTC, Shriramana Sharma
> > via Digitalmars-d-
> >
> >> I submit that the syntax for attributes should be streamlined.
> >> Shall I
> >> go and open a Bugzilla item?
> >
> > No need: http://wiki.dlang.org/DIP64
>
> Besides the @ symbols, isn't there also some inconsistency on
> whether attributes go before or after the declaration?
>
> @property public static void foo() const @safe pure nothrow
>
> I've never bothered to ascertain how much of the positioning is
> optional, but definitely none of it makes sense.

Yeah. Some attributes are legal on both sides, others on only one, and I'm not
aware of much logic to it (though at the moment, I don't think that there are
any that are only legal on the right, so you could get away with just putting
them all on the left). I think that it's primarily attributes that exist in
other languages (and go on the left in those languages) that have to go on the
left (e.g. public, private, static). Most (all?) of the D-specific ones can go
on both sides. The ones that actually cause problems with that though are
const, immutable, inout, and shared, because without parens, when they're put
on the left, they still affect the function and not the return type, so quite
a few of us have argued that they should be illegal on the left.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list