Add := digraph to D

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 20 10:18:56 PDT 2012


On Wednesday, June 20, 2012 16:36:47 ixid wrote:
> Is there any reason not to add this so you can use foo := bar as
> a shorthand for auto foo = bar?

Any proposed feature must have a solid use case and reason for being in the 
language. It needs to add real value. If you want a feature in the language, 
you need to show why it's truly worth having. This is especially true at this 
stage in the game. The language is supposed to be essentially stable at this 
point. We're ironing some stuff out still (primarily due to the compiler being 
behind the language definition), but we're not looking to make changes without 
good reason. And breaking changes _really_ need a good reason.

As for your particular suggestion, I don't see how it adds anything but 
complication. So, you write

foo := bar;

instead of

auto foo = bar

_All_ it is is a syntactic change. It saves you a few characters. It adds _no_ 
new functionality. It just adds one more thing that someone learning D has to 
learn and know. And it's not at all in line with how variable declarations 
normally work. What we currently have is very consistent. := doesn't fit in 
with that at all. For all variable declarations, we have

Type name = initializer;

In some cases, the type is inferred, but then type specifier is used in its 
place:

auto name = initializer;
const name = initializer;
immutable name = initializer;
shared name = initializer;
enum name = initializer;

If we implemnted your suggestion, then we'd have

name := initializer;
auto name = initializer;
const name = initializer;
immutable name = initializer;
shared name = initializer;
enum name = initializer;

It _only_ covers the auto case, and it doesn't fit in with the rest at all.

Not to mention, there are some programming languages (e.g. Pascal) which use 
:= for normal assignment, so it would be confusing for anyone familiar with 
those languages. I'm not aware of any language which specifically uses := for 
auto, just for assignment (though if the language doesn't require variable 
declarations, then all assignments are essentially the same as declarations 
with auto). So, what you're proposing (AFAIK) would be a new usage for :=, 
even if it's similar to what other languages have done.

If you want something like this added, you need a compelling use case, and you 
don't seem to have one.

- Jonathan M Davis


More information about the Digitalmars-d mailing list