My two cents

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Oct 21 00:23:13 UTC 2017


On Friday, October 20, 2017 15:25:20 Adam Wilson via Digitalmars-d wrote:
> So far I have seen three arguments proffered for the ban syntax sugar.
>
> The first is "Walter/Andrei doesn't have the time."

That actually has pretty much nothing to do with a feature request like
syntactic sugar - especially if it's trivial to implement. Andrei in
particular seems to feel strongly at this point that if something can be
reasonably done with how the language is right now, then we don't need to
add a feature for it. And if that's the case, then syntactic sugar stands
pretty much no chance of getting in regardless of how easy it is to add. He
even had some _removed_ after the work had already been done and merged -
specifically using [$] in a static array declaration to infer the type,
which we can't even fully do with a library right now thanks to
https://issues.dlang.org/show_bug.cgi?id=16779.

> The second argument is "the language is already powerful enough to let
> you do that." This argument is specious. Yes, the language is powerful
> enough to do those things without syntax sugar. But syntax sugar isn't
> about power, it's about efficiency. So I certainly can write a function
> that does what ?. does but as we've already seen in this thread, there
> are multiple ways to name it. So far I've seen orElse and getOr. This
> creates a dialectic friction, whereby when moving to a new codebase I
> have to learn these new shibboleths. Those methods may function
> identically or they may have frustratingly subtle differences in
> implementation, and I have absolutely no way to know from reading the
> calling code.
>
> By adding syntax sugar we standardize these idiomatic shibboleths. This
> improves the overall code read/write efficiency by standardizing both
> the language construct and the implementation of the idiom. Of course
> you are still free to write the non-idiomatic methods you need. And
> indeed, by standardizing the common idiom, it becomes trivial to
> differentiate the standard idioms from the non-standard idioms. This is
> a two-stage win for the language.

Well, I think that you'd need to prove that the syntactic sugar objectively
improved a lot of existing D code to stand much chance of convincing Andrei.
My guess is that you have a better chance with Walter, but I don't know.
Regardless, I think that it would need to be shown that the proposed syntax
would be a significant improvement to a lot of the existing code out there.
Andrei in particular seems to be becoming more insistent on that point and
less likely to agree that something is worth adding to the language when it
can be done with a library solution.

Personally, I see little value in any of the suggested syntactic sugar
involving ?; either we already have a library solution that works just fine
(e.g. Nullable), or it's something that I do so rarely in my D code that,
I'd likely never use it. There probably are a few places in Phobos where
they could be used, but idiomatic D code simply doesn't do much with null.
Structs are heavily used, whereas classes are rarely used, and dynamic
arrays (strings included) are designed so that null and empty are mostly
synonymous. And while pointers do get used some, the focus is generally on
static allocations where possible, which significantly reduces the number of
heap allocations in comparison to typical C# or Java code. Particularly,
when doing a lot with ranges, null doesn't tend to enter into things much. I
rarely find that I need to check for null.

But anyone wanting such additions would need to convince Walter and Andrei,
not me.

- Jonathan M Davis



More information about the Digitalmars-d mailing list