D community's view on syntactic sugar
Meta
jared771 at gmail.com
Sat Jun 16 06:33:44 UTC 2018
On Saturday, 16 June 2018 at 05:48:26 UTC, Nick Sabalausky
(Abscissa) wrote:
> Everyone here is probably going to be different (D programmers
> are a varied bunch), but for me, I absolutely love syntax
> sugar. And I very much miss the earlier days when D was all
> about the sugar.
Funny that you mention that. Back 6 years ago when I was looking
for a C++ alternative that wasn't Java, and came across D (I
think I saw it mentioned on Bartosz Milewski's site somewhere),
there were exactly three things that took me from "okay, this is
kind of cool" to "man, this looks awesome. I need to jump in and
start learning this language right away":
Array slicing (no brainer)
Array operations (like a[] *= 3)
Built-in complex numbers
At the time though, I thought it was so cool that there was a
language that had syntactic sugar like this (I was an undergrad
student at the time, and I was getting really tired of having to
write out for-loops in Java - never mind that I think Java had
introduced for-each syntax at this point).
The fact that
for (int i = 0; i < array.length; i++)
{
array[i] *= 3;
}
Could be replaced with a one-liner in D just blew my mind.
Same for complex numbers, I guess. I don't generally care about
complex numbers and rarely use them, if ever, but I just thought
it was so cool that having them built-in made the code so
straightforward and beautiful.
>> * a good syntax for properties so there's less code bloat.
>
> That bugged me for awhile, too, due to my earlier C#
> experience...
I wrote a lot of C# a few years ago working on a big project for
my then-employer, and I missed a lot of D features. However, the
one thing I think I miss the most in D is C#'s getter/setter
syntax. I hate using properties in D, because they are not
transparently substitutable with bare members (even when we
assume no static introspection), and because it requires two
separate declarations to define both a setter and a getter
function.
> If only D hadn't given up on the AST macros idea, we could
> actually implement most of this sugar AS A LIBRARY SOLUTION,
> just like modern D wants.
I do wish D had some sort of procedural macro system a la what
they're trying to do in Rust. The template systems C++ and D have
now are just clumsier macro systems with a fraction of the power
and double the complexity.
At this point, it's a matter of taste, and Walter and Andrei's
taste differs from mine. The only way I can truly get what I want
from the D language is to fork it, which I don't have the time or
knowledge to properly maintain. Maybe once I retire and get fed
up with D, like Walter with C++, and thus the cycle begins anew
;-)
More information about the Digitalmars-d
mailing list