The stately := operator feature proposal

nazriel spam at dzfl.pl
Thu Jun 6 09:13:29 PDT 2013


On Thursday, 6 June 2013 at 16:06:44 UTC, Tyler Jameson Little 
wrote:
> On Friday, 31 May 2013 at 00:57:33 UTC, Minas Mina wrote:
>> I don't think this is useful.
>>
>> At least when I see "auto" in the code I immediately 
>> understand what's going on, whereas with this proposal I have 
>> to double check my code to see if it's ":=" or "=".
>
> First off, I write a _lot_ of Go code, and I _love_ the := 
> there. It makes things nice and simple, and it fits nicely into 
> the rest of the Go syntax. However, I don't think it belongs in 
> D because it changes the flow of the code.
>
> The problem is where type specifiers are expected to go. In D 
> (and most other C-like languages), types go before the 
> identifiers:
>
>     int x, y, z;
>
> When scanning code, if I see a type identifier, I know it's 
> declaring something. I immediately know the scope and all is 
> well.
>
> In Go, types go after the identifiers:
>
>     func example(x, y, z int) {}
>
> This is only broken by var|type, which are completely different 
> expressions.
>
> For Go, the := makes perfect sense, because when you read Go 
> code, you expect the identifier first, then the type. In D 
> however, nothing else (correct me if I'm wrong) has this syntax.
>
> I have no problem with the := syntax, I just think it doesn't 
> make syntactic sense. It subtly breaks the idioms of the 
> language, all for very little gain.

So maybe =: for D? :P
Naa, just kidding.
>
> I would be okay with type blocks, or the presented math {} 
> block (which could do all sorts of new and exciting things) 
> because that would fit more nicely into the language.
>
> If the OP really wants this, he/she can easily write a 
> pre-processor for D code that he/she uses on his/her own 
> personal projects. A completely untested regex:
>
>     rsync src compilable-source
>     find compilable-source/ -name "*.d" -exec sed -i 
> "s/\(\\w+\)\\s*:=/auto \1 =/g" {}+
>
> There, feature done in two lines of shell...

+1

AFAIK Namespace (user with such nickcname) already wrote 
preprocesor for D with syntax candies he likes.

I bet if math guys were so interested in D they would do the same 
at some point.

I personally don't care about that :=. Probably won't use as I am 
already familiar and fine with auto. I believe though that 
letting achieving same thing in different ways will just bring 
troubles.


More information about the Digitalmars-d mailing list