D community's view on syntactic sugar
Neia Neutuladh
neia at ikeran.org
Sun Jun 17 16:52:59 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 `?.`
Null-safe dereference operator, I think it's called?
Hrm, my first impulse was in favor. I find this useful in Kotlin
and I miss it when using Java. In D, I don't encounter null very
often at all.
> * Something like a `yield return` statement for coroutines.
For iterables, more like? If you want a userspace thread, Fiber
gives you this. But it can be annoying right now to write a range.
> T* he `async` & `await` keyword from C# make proactor pattern
> async code extremely easy to reason about.
http://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/
Maybe not the best. It's useful when you want to execute a small
fixed number of heterogeneous things in parallel, but the cost is
that everyone has to choose whether to make their thing run
asynchronously or synchronously, and there's going to be pressure
to make everything that could take more than a few milliseconds
to go asynchronous. This would force almost every program to be
multithreaded.
> * a good syntax for properties so there's less code bloat.
C# has syntax like:
public int Something { get; set; }
It does this to make it easier to switch out a field for a
computed property, to add validation to a field, and to let you
put properties into interfaces.
D code typically doesn't use interfaces much, and you don't have
to do anything special to convert a field into a getter/setter
pair.
The only case where D loses out is compared to { get; private
set; }.
> * 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?
allocator.make!Foo(args)
new!allocator Foo(args)
One character difference. Doesn't seem like a big deal.
More information about the Digitalmars-d
mailing list