logoalt Hacker News

Someonetoday at 8:11 AM1 replyview on HN

I don’t think that’s a valid comparison. It compares two entirely different cases.

In general, if the guts of Foo are similar to those of Bar, translating Foo to Bar is fairly easy.

If Foo has additional guts, as in the C++-to-ℂ translator, translating those parts can lead to hard to read code.

In the C-to-D translator case, it’s not Foo that has additional guts, though, but Bar.

Then, a reasonable 1:1 transaction is easy. Doing it in idiomatic style can still be hard, though. For example D has garbage collection, classes and inheritance. I doubt the readily translation of C to D will replace C equivalents (e.g. a garbage collector written in C that’s part of the code) by those where possible.


Replies

WalterBrighttoday at 6:27 PM

It's true that D has many features that are not part of C, and a translator from C to D will not recognize constructions in C meant to exhibit inheritance. It's also true that a C to D translator will not be able to translate metaprogramming done with the C preprocessor.

It is a valid comparison, though, as there is no point to designing a language that has a 1:1 mapping to/from C.