Top
Best
New

Posted by vips7L 3 days ago

Features of D That I Love(bradley.chatha.dev)
196 points | 249 commentspage 2
zzo38computer 3 days ago|
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 3 days ago||
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 3 days ago||
UFCS is a bit overreaching but I think it's great for its intended use of chaining expressions on ranges and such.
destructionator 3 days ago||
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 2 days ago||
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 3 days ago||
D is one of the most beautiful and very efficient language. I wonder why it never got the attention it deserves.
Joker_vD 2 days ago||
> Invariants are functions that run at the start and end of every public member function, and can be used to ensure that the type is always in a valid state.

The ironic thing about this is that it means that the public functions of an object can't, generally, call each other willy-nilly unless they take special precautions: very often, the object's invariants are broken when the execution is in a middle of the object's method. This is not a problem with D, the language merely helps you to uncover this lurking problem which usually simply goes unnoticed until something breaks and someone notices it.

WalterBright 1 day ago|
Yes, a subtle but very important point!
kwoff 3 days ago||
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 3 days ago||
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 2 days ago||
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 2 days ago||
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 2 days ago|
Am I missing something? Those three keywords are literally in the same order in all the examples.
p0nce 2 days ago||
Sorry, those keywords work in block like those, or relatively to a single function, in any order.
randomNumber7 2 days ago||
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 2 days ago|
All wonderful features. Design by Contract in particular is massively underused in mainstream languages.
More comments...