On Wednesday, 20 June 2012 at 17:19:08 UTC, Jonathan M Davis
wrote:
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
It's from Go, which has proper tuple syntax, it's main use is
that it allows
you to declare a new var and reuse an old one. So it would be
worth looking in to when we introduce a proper tuple syntax, but
not now.
Unlike regular variable declarations, a short variable
declaration may
redeclare variables provided they were originally declared in
the same block
with the same type, and at least one of the non-blank variables
is new. As a
consequence, redeclaration can only appear in a multi-variable
short
declaration. Redeclaration does not introduce a new variable; it
just assigns
a new value to the original.