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

Martin Nowak via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 10 08:15:04 PDT 2014


On 10/10/2014 04:37 AM, Walter Bright wrote:
> On 10/9/2014 1:50 AM, Martin Nowak wrote:
>> 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.
>
> This has come up before, and has been debated at length.
>
> const is used both as a storage class and as a type constructor, and is
> distinguished by the grammar:
>
>     const(T) v; // type constructor, it affects the type T
>
>     const T v;  // storage class, affects the symbol v and the type of v

That on it's own is fairly difficult to explain.

> For functions, const-as-storage-class applies to the function symbol.

What's the difference between a const symbol and a normal symbol?

> This endless search for the ideal syntax is consuming our time while we
> aren't working on issues that matter. (And this change will consume
> users' time, too, not just ours.)

Sure, programmers are obsessed with syntax discussion. Think of all the 
future time that is wasted discussing whether const on a function should 
be left or right.

> If we're going to break things, it needs to be for something that
> matters. This doesn't make the cut.

There are 3591 open issues in bugzilla and hundreds of ideas floating 
around. So there will always be a lot of unplanned things happening in 
parallel. I do agree that we should handle such proposals early on 
through DIPs rather than stopping finished work in a pull request.

We don't want to break code, but discourage the usage of LHS function 
qualifiers because they are confusing.
As this is more about stating a clear preference than deprecating the 
old syntax let me propose a compromise.

- adding RHS rule to D's style guide http://dlang.org/dstyle.html
   with an explanation what the storage class function thing does

- change any dmd formatting code to RHS and change our documentation

- leave the rest to linting tools like 
https://github.com/Hackerpilot/Dscanner


More information about the Digitalmars-d mailing list