Add := digraph to D

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 20 11:58:20 PDT 2012


On Wednesday, June 20, 2012 19:59:08 ixid wrote:
> I see that this is not going to happen for D2 but as a debate for
> a future D3 (and please just ignore my post if you find this in
> some way exasperating, I am interested but do not mean to cause
> friction):
> 
> Just as a question about the existing syntax as you listed
> 
> combinations to learn as a negative:
> > auto name = initializer;
> > const name = initializer;
> > immutable name = initializer;
> > shared name = initializer;
> > enum name = initializer;
> 
> After the first aren't these all just short hand for "const auto
> name = init" etc with the given keyword? If your argument is that
> additional cases are bad then this is a case for what appears to
> be syntactic reasons. It feels as if initialization should be
> more explicit than keyword varname. As a beginner I certainly
> found that odder than :=.
> 
> Syntax confusion with other languages is not a strong argument,
> well at least as the confusion is with unrelated languages.
> Fortran uses /= for not equal, Matlab uses ~=, while that is D's
> append to self.
> 
> Terse elegance is important in making languages quick to take in
> and work with, it's not an argument of new function but that is
> not the only reason to include features, convenience is a good
> reason when there is no ambiguity.

A language can certainly use whatever syntax it wants to, but if it uses a 
syntax that no other language uses or reuses a particular piece of syntax for 
something completely different, it comes at a cost in terms learning and 
knowing the language. It's often the case that someone will argue that 
something should be added simply because another language does something in a 
particular way, and use that as an argument. Arguing that something shouldn't 
be added because no other language does it that way is basically the same 
argument but in reverse.

D _has_ done some if its own stuff already (e.g. ~ and ~= for concatenation and 
appending), so the fact that no other language did something a particular way 
is not necessarily a barrier to having D do it that way, but there needs to be 
a good reason for it, and at this stage in the game, we're not gonig to make 
changes like that without a _really_ good reason.

Regardless, := just doesn't match what D currently does. And given that other 
languages have

auto name = initializer;

or something very similar (e.g. IIRC C# uses var instead of auto; C++11 
however uses the exact same syntax as D), auto is very much in line with what 
other languages are doing (regardless of whether any other language uses := in 
a manner similar to what you're proposing). So, whether auto or := is more 
immediately obvious is completely a matter of what your personal experience 
is. It's going to vary from programmer to programmer. Personally, if a 
language uses :=, I would have expected it to be used for what D uses = for 
rather than auto.

Obviously, you're going to have to learn new stuff in learning any language, 
and we're unlikely to change anything at this point simply because someone 
thinks that another language's syntax is better and that D should use it. Even 
if the other syntax _were_ better, it's too late in the game to change it now 
without a really compelling reason. And adding a second way to do things on 
top of the first is just going to make it so that there are _more_ things for a 
D newbie to learn, and D is already far from being small.

Who knows what'll happen with D3. It's years off yet, if it will even ever 
happen at all. What we do with it will be discussed then, so it's pretty much 
irrelevant now. However, I'd be very surprised if we made a minor syntactic 
change like this for it, since it would just make D2 code harder to port to D3 
without providing any real benefit (the only benefit is whatever aesthetic 
benefit a particular programmer might see in using := over auto).

You're free to propose and discuss possible changes for D3, but there's very little
in terms of language changes that are going to happen to D2 at this point
(especially syntactically), and personally, I think that it's a waste of time to
discuss possible changes for D3 given that it's likely 10+ years off and that what
we decide to do with it is going to be highly dependent on the lessons learned
while using D2 over that time period.

- Jonathan M Davis


More information about the Digitalmars-d mailing list