The stately := operator feature proposal

Timon Gehr timon.gehr at gmx.ch
Thu May 30 03:38:09 PDT 2013


On 05/30/2013 10:50 AM, Jonathan M Davis wrote:
> On Thursday, May 30, 2013 09:43:36 Russel Winder wrote:
>> On Thu, 2013-05-30 at 02:19 +0200, MrzlganeE wrote:
>> […]
>>
>>> In places where I write a bunch of short mathy code, I do not
>>> want to use 'auto'. The := operator would allow to declare a
>>> variable, deduce its type, and define its value.
>>>
>>> void main() {
>>>
>>>       x := 1;
>>>       y := 2.0;
>>>       z := x * y;
>>>       y = 3.0;
>>>
>>> }
>>
>> […]
>>
>>>       for (i := 0; i < 24; i++) {
>>>       }
>>
>> Go does exactly this, and it is good.
>>
>> Less is more.
>
> Less would mean not having this syntax,  because it would be adding more to the
> language and therefore increasing its complexity.
>

Not noticeably.

> Personally, I don't think think that the extra complication caused by having
> another syntax for something that we already have is worth it, regardless of
> whether it's aesthetically pleasing or not.
>

The complexity argument is not a strong argument for such a simple 
feature (It takes around 10 minutes to implement in a compiler and 2s to 
learn.), especially given the existing complexity of D.

It simply does not fit nicely into the rest of the D declaration syntax. 
(Which I'd argue is an issue with the C-like syntax of D, but many seem 
to like that.)

> And honestly, I actually think that it would make code _less_ legible.

In my experience, anything that removes excessive verboseness makes the 
code more legible.

> Sure, other languages use this syntax, but the difference between = and := is minor,

It is noticeable at a glimpse. It's simply a matter of getting 
accustomed to new syntax.

> and we already have auto.  So, this adds no functionality whatsoever.
>

It adds functionality to the parser.




More information about the Digitalmars-d mailing list