Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Did you attempt to submit PRs to D for the features you have listed?

It would be indeed quite neat (pun intended) to see D adopt them as well, specially sumtypes, Rust went ahead and made enums better, it's quite an expected feature for a language at this point



Just to clarify for anyone who may misunderstand this: D has sum types: https://dlang.org/phobos/std_sumtype.html

The problem the OP was talking about is that in D, you cannot implicitly use an `int`, say, where `SumType!(int, string)` is expected.

You need something like this:

    alias StrOrInt = SumType!(int, string)

    void takeStrOrInt(StrOrInt s)
    {
      writeln(s);
    }

    StrOrInt value;
    value = 10; // ok
    value = "foo"; // ok

    takeStrOrInt(value); // ok
    //takeStrOrInt(10); // not ok
    //takeStrOrInt("foo"); // not ok

    takeStrOrInt(StrOrInt(10)); // ok
    takeStrOrInt(StrOrInt("foo")); // ok
Even though this is not perfect, it works quite well (I believe it's zero cost to do `StrOrInt(10)` for example, but I'm a D newbie). It's a bit crazy for me to see people creating new languages instead of help improving existing ones because of minor stuff like this. The effort to create a language and a stdlib and a package manager etc. is ridiculously high compared to improving existing languages.


I think you're underestimating the effort cost of D sumtypes at scale. Every individual instance of StrOrInt(10) is cheap, but once you're actually constructing structs in the same line, you end up writing a lot of terrible code like

    publish(TrackingEvent(UpdateTrackerEvent(trackerId, position)));
that just adds visual noise. And the fact that you cannot return out of sumtype apply expressions just makes so many neat idioms impossible. Something like

    Object obj = nullableObj.case(null: return false);
is just fundamentally impossible in D.

So it's not one thing, it's a lot of things coming together. :) Mostly I just realized one day that D was never going to be the perfect language for me, because it wasn't even interested in being that language.

> The effort to create a language and a stdlib and a package manager etc. is ridiculously high compared to improving existing languages.

Have you seen the DMD source code? Genuinely, writing my own compiler was easier than improving DMD.


We're in a DIP freeze right now. But Walter doesn't like macros and implicit conversion. Half the point of Neat is showing D devs there's no reason to be afraid of those powerful features.


I'm getting quite interested in D... can you explain what's exactly going on with DIP1000 and whatever else you may be referring to?

Are the changes to the language going to make it much better? Break existing code? How long until they finish that, is it nearing completion or just beginning now?? So many questions as someone new to D.


I have no idea honestly, it's all sort of in a state of confusion rn. The big thing coming up is editions, but that's not even slightly codified or implemented yet. I'm curious where it's going as well, I'm very hype for that approach. It could end up really good for the language. Or it could all sort of come to nothing. We'll see over the next years.


> DIP freeze right now

So much good has come of it...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: