D community's view on syntactic sugar

Seb seb at wilzba.ch
Sat Jun 16 00:20:35 UTC 2018


On Friday, 15 June 2018 at 23:04:40 UTC, Sjoerd Nijboer wrote:
> For someone coming from a C# background there is some seemingly 
> simple syntactic sugar missing from D.
>
> * The null conditional operator `?.`

e.g. SafeAccess

https://github.com/BBasile/iz/blob/7336525992cb178ead83a7893a5a54597d840441/import/iz/sugar.d#L1551

> * Something like a `yield return` statement for coroutines.

The library solution only has the downside of requiring 
parenthesis:

https://dlang.org/phobos/std_concurrency.html#.yield

> T* he `async` & `await` keyword from C# make proactor pattern 
> async code extremely easy to reason about.

There was some talk about adding async/await to the language once 
we actually get an eventloop library into Phobos/DRuntime.

A very promising approach and project: 
http://dconf.org/2018/talks/olshansky.html

> * a good syntax for properties so there's less code bloat.

It's typically solved with `mixin`.

https://github.com/funkwerk/accessors
https://github.com/funkwerk/boilerplate

There's also somewhere on this forum a nice mixin that generates 
default constructors for you if you don't need any specialization.

> * replacing `Allocator.make()` with `new!Allocator`. After all 
> `new` can be concidered as just a wrapper around the standard 
> GC allocator. Why can't we just have a special template of it?

How would you pass a reference to the allocator object around 
with new!Allocator?

> I have realized that I have become quite dependant on syntactic 
> sugar to the point that it severely impacts my productivity 
> when I work whitout. And these ones are my biggest obstacles 
> when I try to work with D from a C# experience. I think that C# 
> really nailed down some of these particular examples except the 
> last one of course.
> And I also think D could do a better job of embracing 
> productivity through supporting syntax of common tasks and 
> borrow from other languages in that regard.
>
> But the most important question is how other people feel about 
> that.
> If people hate syntactic sugar D will never become that gem for 
> me that I would like it to be. But if key people want it, it 
> one day might.

Don't get me wrong, I like convenience features too - I was just 
trying to point that for most of these things a library solution 
is just one keystroke more effort and allows more rapid iteration 
on the design.

So of course, people obviously like syntactic sugar, but the 
problem is that nowadays one needs a strong argument when trying 
to convince W&A for introducing yet another language feature as 
it bloats the language and makes it harder for newcomers to learn 
it and read code in it. Also in the past a few language features 
haven't turned out to be that great, so that's why nowadays 
there's more caution.
However, there's quite an interest and we regularly do get new 
sugar, e.g. the new contract syntax:

https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1009.md (will be part of the upcoming 2.081)


More information about the Digitalmars-d mailing list