Live data from Hacker News

D 2.069.0 released, compiler automatically ported from C++ to D

dlang.org

21–30 of 131 posts

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#21

Earlier quoted context omitted.

How would you consider Rust's generics as being part of a better C rather than a better C++?

I think it's more about Rust's approach to OO. In Rust, traits are usually used as interfaces for generics instead of dynamic dispatch. The generated code/performance is more like what you would get if you implemented them explicitly for each appropriate type in C, built around structs. You could do this with C++ templates, but it would be a huge pain in that language due to lack of template type safety. This is a qu…

Hmm, I see your point, but I've found that even in template-heavy code the compiler can produce code that's pretty optimal. Are you saying that with Rust it is easier to fall into the pit of success, as it were -- requiring less reasoning about how a compiler might convert the [templated|generic] code optimally?

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#22
post #19

Earlier quoted context omitted.

How would you consider Rust's generics as being part of a better C rather than a better C++?

C translates almost 1:1 to Rust, but when converting C++ to Rust you'll run into impedance mismatch between OO hierarchies and traits, and generics being narrower in functionality than templates. In Rust you still can do "clever" things with generics to make them feel like C++, but the rest of the language is still closer to C: errors returned rather than thrown, no inheritance (but the "flat" OO and enums map well t…

Really? Now I have to go learn Rust.

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#23

Earlier quoted context omitted.

I think it's more about Rust's approach to OO. In Rust, traits are usually used as interfaces for generics instead of dynamic dispatch. The generated code/performance is more like what you would get if you implemented them explicitly for each appropriate type in C, built around structs. You could do this with C++ templates, but it would be a huge pain in that language due to lack of template type safety. This is a qu…

Hmm, I see your point, but I've found that even in template-heavy code the compiler can produce code that's pretty optimal. Are you saying that with Rust it is easier to fall into the pit of success, as it were -- requiring less reasoning about how a compiler might convert the [templated|generic] code optimally?

My point was not that Rust creates better template code, but that a lot of things one uses dynamic dispatch for in C++ use templates instead. There are plenty of times when one knows the full derived type of a class in C++, but one throws away that information virtual calls are used anyway.

I think this is because Rust makes it far easier to use generics; they're type-safe and don't need to be pushed to header files. Also, the coding culture around Rust pushes one to use enums for dynamic dispatch instead of "trait objects" (Rust's equivalent of VFTs).

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#24

Daniel Murphy is the man behind getting the sources converted from C++ to D. He wrote a program called "magicport" to do the bulk of it, with some manual tweaking. The back end is still in C++, showing that you can mix D and C++ code :-)

How is the compiler bootstrapped now (i.e. compiled from source without a working D compiler)? Via the gcc D implementation?

Using the previous version write on C++. Like all compilers of other languages did when change to be write on his own language. Or do you think that the first version of C compiler was write on C ?

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#25

Daniel Murphy is the man behind getting the sources converted from C++ to D. He wrote a program called "magicport" to do the bulk of it, with some manual tweaking. The back end is still in C++, showing that you can mix D and C++ code :-)

Now all we need is some E to celebrate!

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#27
post #3

I'm wondering, is there an advantage of using D over Rust?

Some things D has that Rust doesn't: compiler-checked function purity annotations, higher-kinded types, variadic functions/generics, types parameterised by numbers, compile-time function evaluation, mixins, a fast compiler (the reference DMD compiler), powerful and convenient compile-time reflection (I think technically Rust can do anything D can at compile time, but it requires writing a syntax extension to do so).…

On the nontechnical side I would add that since D is a lot older, keeping up with changes is a whole lot less challenging. Its stable enough that one can put it near the money without worrying too much about breaking changes.

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#28
post #5
post #3

I'm wondering, is there an advantage of using D over Rust?

I guess D feels more like a better C++ and Rust like a better C, but I may be under the wrong impression.

I disagree. D is an improved C that does a lot of the same things as C++, but in order for it to be a better C++, it would need to start with C++ as a foundation and build on it. D has more of a scripting language feel to me.

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#29

Earlier quoted context omitted.

Hmm, I see your point, but I've found that even in template-heavy code the compiler can produce code that's pretty optimal. Are you saying that with Rust it is easier to fall into the pit of success, as it were -- requiring less reasoning about how a compiler might convert the [templated|generic] code optimally?

My point was not that Rust creates better template code, but that a lot of things one uses dynamic dispatch for in C++ use templates instead. There are plenty of times when one knows the full derived type of a class in C++, but one throws away that information virtual calls are used anyway. I think this is because Rust makes it far easier to use generics; they're type-safe and don't need to be pushed to header files.…

> but one throws away the information ...

With the mythical smart enough compiler with god like devirtualizer it would be less of an issue but gratuitous use of virtuals annoys me no end. CRTP isn't that hard for the simple use cases but you are beholden to the god of compiler error messages when things go wrong. One great thing that clang has done (among others) is make g++ get their shit together. Contrary to the popular sentiment I personally find the current crop of g++ error messages more helpful.

Re: D 2.069.0 released, compiler automatically ported from C++ to D

#30
post #27

Earlier quoted context omitted.

Some things D has that Rust doesn't: compiler-checked function purity annotations, higher-kinded types, variadic functions/generics, types parameterised by numbers, compile-time function evaluation, mixins, a fast compiler (the reference DMD compiler), powerful and convenient compile-time reflection (I think technically Rust can do anything D can at compile time, but it requires writing a syntax extension to do so).…

On the nontechnical side I would add that since D is a lot older, keeping up with changes is a whole lot less challenging. Its stable enough that one can put it near the money without worrying too much about breaking changes.

Since 1.0 last May, we have a strong commitment to backwards compatibility as well. Stability should not be an issue any longer.
Post reply on HN