Top
Best
New

Posted by vips7L 7/2/2025

Features of D That I Love(bradley.chatha.dev)
198 points | 258 commentspage 2
burnt-resistor 7/3/2025|
Invariants, dependent typing, and refinement types FTW.

In Rust land, it really need integration of something like flux into the language or as a gradually-compatible layer.

Can't have safe software without invariant checking, and not just stopping at bounds checking.

zzo38computer 7/3/2025||
In my opinion, some features of D are good, but I do not like all of them.

CTFE is good.

I do not really like the UFCS; if you want it to be used like a member of the first parameter then you should define it as a member of the first parameter (possibly as a inline function that only calls the freestanding function with the same name, if that is what you want it to do). (You could use a macro to do this automatically if you want to.)

Scoped imports is good, but I think that scoped macros would also be helpful.

Exhaustive switch seem like it might be better if designed differently than it is, but the idea seems to be not bad, in general.

Doxin 7/3/2025||
Honestly the main reason UFCS is good is when you don't "own" the type your function would need to be a member of. Most common one I run into is the "to" function from the stdlib. You can do this:

    import std.conv;
    
    int foo=3;
    string bar = foo.to!string
But now lets say you want to convert ints to MyCustomInts? You can hardly attach a new "to" member to int, but with UFCS it's easy. Just declare a to function anywhere in scope:

    MyCustomInt to(T)(T v) if(is(T==int)){
        return MyCustomInt.from_int_value(v)
        // or however you actually do the conversion
    }
and it'll magically work:

    int foo=3;
    MyCustomInt bar = foo.to!MyCustomInt;
LorenDB 7/3/2025||
UFCS is a bit overreaching but I think it's great for its intended use of chaining expressions on ranges and such.
destructionator 7/3/2025||
that actually wasn't its intended use; that's a side effect. The original intended use came from Effective C++ by Scott Meyers: "Prefer non-member non-friend functions to member functions.". It was meant to make that as syntactically appealing as the members.
RcouF1uZ4gsC 7/3/2025||
The reason that D did not replace C++, IMO is garbage collection.

D was so far ahead of C++98 that it wasn't funny, but garbage collection kept it from being able to be used in the same niche.

D has gotten less dependent on garbage collection but

C++11 (and then 17, 20, 26 (reflection)) have closed the gap enough that it is not the quantum leap that it once was.

tealpod 7/3/2025||
D is one of the most beautiful and very efficient language. I wonder why it never got the attention it deserves.
kwoff 7/3/2025||
Dlang always makes me think of two things: Walter Bright, resident of Hacker News. And awesome games I played on Linux in the 2000s: https://en.wikipedia.org/wiki/ABA_Games
bachmeier 7/3/2025||
Interesting that there's nothing on there about C interop (likely reflecting the use cases of the author). D does it all: ImportC (compile C code), BetterC (make a D library part of a C program), and easy C interop in both directions.
skocznymroczny 7/3/2025||
I hope some day D gets some WASM story going. Right now the support is very limited, pretty much only through the C subset of D which defeats the point. Supposedly the GC was the main issue, but other GC enabled languages are already thriving in the Web (Go, Java, C#).

There were some efforts to enable D on the web but it seems like these are mostly one man efforts that implement only the minimum features that their specific projects required.

p0nce 7/3/2025||
Strangely my favourite feature after 18 years of D programming (!) is that could place keywords largely in the order you like. It is strangely liberating to be able to put:

    pure nothrow @nogc: 
or

    pure:
    nothrow:
    @nogc: 
or

    pure nothrow @nogc
    {
        block
    } 
Sometimes this helps readability.
quietbritishjim 7/3/2025|
Am I missing something? Those three keywords are literally in the same order in all the examples.
p0nce 7/3/2025||
Sorry, those keywords work in block like those, or relatively to a single function, in any order.
randomNumber7 7/3/2025||
When I last looked at D they did a lot of interesting stuff with compile time function execution and s.th. like dependent types that they hacked into the language.

Can someone give me an update about the current state of this?

sirwhinesalot 7/3/2025|
All wonderful features. Design by Contract in particular is massively underused in mainstream languages.
More comments...