Make const, immutable, inout, and shared illegal as function attributes on the left-hand side of a function

Marco Leise via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 00:42:38 PDT 2014


Am Thu, 09 Oct 2014 10:50:44 +0200
schrieb Martin Nowak <code at dawg.eu>:

> Kenji just proposed a slightly controversial pull request so I want to 
> reach out for more people to discuss it's tradeoffs.
> It's about deprecating function qualifiers on the left hand side of a 
> function.
> 
> So instead of
>      const int foo();
> you'd should write
>      int foo() const;
> 
> Then at some future point we could apply the left hand side qualifiers 
> to the return type, e.g. `const int foo();` == `const(int) foo();`
> 
> Would this affect your code?
> Do you think it makes your code better or worse?
> Is this just a pointless style change?
> Anything else?
> 
> https://github.com/D-Programming-Language/dmd/pull/4043

I write my function signatures like this now and I'm fine with
the change:

@safe pure nothrow @nogc [<1]
final override @property ref [<2] int foo() shared const [<3]
{
   ...
}

[1] Attributes that hint the compiler by narrowing down
    allowed language features.
[2] Visibility and behavioral attributes.
[3] Modifiers for implicit `this`.

-- 
Marco



More information about the Digitalmars-d mailing list