It is the year 2020: why should I use / learn D?

kinke kinke at libero.it
Wed Nov 14 17:22:50 UTC 2018


On Wednesday, 14 November 2018 at 15:07:46 UTC, lagfra wrote:
> By 2020 C++ is planning to introduce:
>
> * Ranges

Still no slicing, right? array[1 .. $-1] is just so handy.

> [...]
> Right now it already has:
>
> * `auto` variables

I hate having to type `const auto bla = ...`. With D, it's just 
`const bla = ...`.

> * Ranged for (`foreach`)

But not an implicit 2nd version with index. `foreach (i, e; 
range) { ... }` comes in handy if you need the index too.

> * Lambda expressions and closures

const auto lambda = [...](T param) { ... };
In D, that can be `(T param) => <expression>` or a nested 
function, both much more readable.

> * `nothrow` attributes
> * Proper containers
> * Proper RAII

But no distinction between value and reference types, i.e., D's 
distinction between structs and classes.

> TL;DR: what will D offer with respect to C++ when almost all 
> key features of D are present in C++20(+)?

Some other things coming to mind OTOH:

* *Much* saner templates, no std::enable_if<> crap etc., and of 
course static if. static foreach may also be interesting in some 
cases.
* Builtin associative arrays. std::unordered_map<Key, Value> => 
Value[Key].
* Sane basic types. No need to include a header for the 
definition of `size_t`, no distinct basic types overlap (C++ 
long, wchar_t etc.; not 4 distinct types for a byte - C++ `char`, 
`signed char`, `unsigned char`, and planned `utf8_t`].
* `alias this` for simple decorators without boilerplate at all.
* Pretty good interop with C++, and that's constantly getting 
better.
* User-defined attributes.
* Built-in unittests and documentation.

I surely missed some other cool features.


More information about the Digitalmars-d mailing list