does D already have too many language features ?

Dennis dkorpel at gmail.com
Sun Apr 14 20:24:24 UTC 2019


On Thursday, 11 April 2019 at 18:45:48 UTC, Nick Sabalausky 
(Abscissa) wrote:
> Put simply: The question itself is flawed.

Allow me to alter the question then:

Are D's features too situational / not orthogonal enough?

Take for example these D features:
-debug() statement
-version() statement
-if statement
-static if statement
-ternary operator (condition ? iftrue : iffalse)

Now take the language Zig, which has just if. The if-statement 
there is also an expression, and together with lazy evaluation it 
spans an area covering those 5 D-features and more.
Add first-class types, and you have generics (no need for 
templates, is-expressions, traits).
Add a bottom type (`noreturn`) and you won't need a no-return 
pragma and special assert(0) semantics. Things like 'break' can 
be an expression too now.

Zig may not be as expressive as D, but it gets its expressiveness 
from just a few rules. Having many features available doesn't 
mean you actually 'span many dimensions', since features can be 
restricted. Reading the recent __mutable proposal:

"__mutable can only be applied to private, mutable members." [1]

This is more special logic in the language, indicating __mutable 
is another situational feature instead of a flexible mechanism 
that can be combined with the rest of the language, creating 
another 'dimension'. Of course there's rationale; it's introduced 
to tackle a specific problem, and I don't have a better 
suggestion either. I'm afraid however that a stream of new 
situational features leads D down the same path as C++, just a 
few kilometers behind because C++ had a head start.

Other examples of non-orthogonal features in D are:
- foreach ranges (0..10) and switch case ranges (for general 
number ranges you need Phobos)
- int notInitialized = void; (special case, doesn't follow at all 
from the type-system)
- the many lexical constructs (3 comment types, I don't know how 
many string literals)

I'm not saying D is bad per se for having more features than 
necessary, and I do think version() and debug() have merit over 
if-statements. But lots of features with own rules and special 
casings aren't necessary to have a versatile toolbox.

In conclusion I don't agree with the 'bigger toolbox is better, 
just pick what you need' notion, even ignoring implementation 
costs.

[1] 
https://github.com/RazvanN7/DIPs/blob/Mutable_Dip/DIPs/DIP1xxx-rn.md


More information about the Digitalmars-d mailing list