Hacker News new | past | comments | ask | show | jobs | submit login
Why hasn't D started to replace C++ (quora.com)
35 points by systems on Jan 31, 2018 | hide | past | favorite | 51 comments



From what I'm seeing on GitHub, Rust has beaten it to the punch, mightily.

Levien's Xi video today being yet another example.

edit: As for why, languages are more of a battleground than a substrate. If you have a choice between Swift (Apple), Rust (Mozilla), Go (Google), or D (Walter Bright), most people are going to flock to one of the bigger forces.

Golang is a kind-of underwhelming riff on Pascal, but I use it anyway for network stuff. Why? Google has given it an instant ecosystem with plenty of well tested libraries, docs, and howtos. Never underestimate the ecosystem.


In lieu of a mega corporation behind you, having a killer app to get people interested seems valuable. Ruby would still be niche without rails for instance, .net would have been an uninspiring java clone without MS RAD tools. You can't just have a good language, you need to show the world that it can be used to build good software.


I'm really impressed with the Clojure community. They have done a great job sans-megacorp.


It helps to have a good language to attract those people.


I believe a related question to ask is: How many new projects are started in that niche?

C still seems to spawn new software because people are working directly with hardware and don't wish to code using straight assembly. I'm thinking computer engineering related fields. Robotics for example.

C++ falls into an uncanny valley, it is neither high level language with all of the benefits (e.g. programmer efficiency, certain security guarantees, lower barrier to entry) or a completely low level language (or at least it isn't if you want to benefit from most of C++'s advantages over straight C; you'll avoid a garbage collector but not a lot of "magic" behind the scenes).

C++ carved out a space with 3D gaming for a while but with many development houses moving to licensed game engines or targeting mobile platforms C++'s benefit may be waning.

The data does support this supposition[0].

[0] https://www.tiobe.com/tiobe-index/cplusplus/


> C++ falls into an uncanny valley, it is neither high level language with all of the benefits (e.g. programmer efficiency, certain security guarantees, lower barrier to entry) or a completely low level language (or at least it isn't if you want to benefit from most of C++'s advantages over straight C; you'll avoid a garbage collector but not a lot of "magic" behind the scenes).

There are lots of high-level, cost free niceties that C++ provides that I miss when I have to fall back on C. Generics and RAII alone are quite nice.


Advanced robotics is utterly dominated by C++.


Advanced everything is utterly dominated by C++.


Not lower bit microcontroller programming which is still dominated by C. (Because C++ compilers do not exist or produce worse code.)


>Because C++ compilers do not exist or produce worse code.

I am surprised this is still true in 2018. GCC and Clang on x86 with -fno-rtti and -fno-exceptions produce almost identical code for similar programs in C and C++.

If what you say is true, I suppose there aren't enough compiler devs paid to optimize C++ for those platforms.


GCC and Clang are not even a thing in most microcontrollers.

You buy the compiler from the same vendor that is selling you the hardware.

Even if it is based on gcc, it happens to be a fork with changes they don't easily release. Some of them are now transitioning to clang, because the license makes it easier to keep doing so.

Many of them are still mostly C89 (not 100% ANSI C compliant due to hardware limitations) with a few C99 features.


Exactly the point. Keil doesn't care and gcc devs on smaller platforms are almost always volunteers.

Clang/LLVM is not even close to supporting something lower bit.


i think the best hope for D is not to replace any language, or dominate any domain

but to be a player

there will always be systems written in different languages for different reasons, or for small advantages of one language over the other

there is a place for C# and Java , a place for rust and go, a place for F# and Clojure, a place for Pythong and Tcl/Tk, etc ..

D from the little i know of it, is a nice language, I dont think it will ever dominate anything or replace anything .. but it definitely has a place .. or deserves to have a place


It was closed source when it was gaining mindshare. So they missed the boat


Cpp was my first language. It seems like I choose languages based upon the project, and it along with Java or JS or python tend to be what's needed for my interests. I guess to me it is simply a tool. So if some killer tech preferred D, then I would pick it up probably. I do avoid many Cpp features, I am just working with a subset usually, for better or worse.


D looked cool when I was struggling to learn C++, and got a little bit of buzz on some sites I was active on, like gamedev.net. That was 12-15 years ago.

I'm just not sure that middle ground between C++ and Java/C# is terribly compelling, and has also been swamped by later entries like Rust, Swift, and Go, which additionally have major backers.


GC, no bigger-player backing, backend was propriety for a long while, and till fairly recently it wasn't a community project, but a one-man work.

D is generally a much better Go (especially if you add fibres to it), but it doesn't have Google-brand behind it, so Go ate it's lunch in distributed systems space, while Rust is much better suited to be a serious competition to C++.


>and till fairly recently it wasn't a community project, but a one-man work

All of D except the backend was open-sourced in 2011, I'm pretty sure. Even before that, Walter Bright accepted patch submissions.


> Rust is much better suited to be a serious competition

why ?


Performance and memory control -- these are the main reasons why people choose C/C++ nowadays and Rust tries to fit in as well. D, as stated in article, is more of Java competitor than C++, because it's slow and use GC.


If you use LDC or GDC, the code generation for D is the same as for C and C++, if the code is written the same way.

The code generation for DMD has fallen a bit behind, mostly because I spend my time on other issues these days :-(


>because it's slow

Where do people get this from? D compiles down to the same machine code that every other compiled language does and it has similar language semantics to C++. In some cases D is _faster_ because its richer type and effect systems allow for more opportunities for optimization.


D uses the GC by default - it's not required. As for speed, it's the same as C++.


Better marketing.


Better marketing... which requires financial resources that D doesn't have.


I don't think Rust's marketing is fueled by money. They just have a lot of vocal supporters.


It's not a big enough improvement over C++ to warrant switching.


legal D:

    if(foo)
        bar();
        baz();
A language design bug copied from C. A feature that is good only to add a class of bugs to programs in your language with zero benfit. Perl wasn't tasteless enough to copy that. D designers were, does that convince you they have the right taste to design your systems language?

Alexandrescou is exactly the kind of C++ person D is designed for (and now by). Is the code more important or the data transformation being performed by that code? Garbage collection, same as golang with the same perception that it's a replacement for java/python/ruby/perl not C nor C++ - this will be the perception and they will say "yeah but ..." sure, but that perception is not devoid of merit. "You don't need ..." nup, as an engineer I decide that, I don't want it imposed.

Low level access to raw hardware, zero cost convenient abstractions, no runtime cost imposed by the language, consistent, easy to get right (or at least harder to get wrong, less gotchas). Whatever replaces C & C++ will tick those boxes unless hardware changes dramatically. People believe that D doesn't.

Then there's just practical stuff like using facebook's linter - well you can't, it just doesn't work. https://github.com/facebookarchive/flint Is the D version even there? Too hard, too alpha, the overhead of a new language needs more to sell it. I haven't yet programmed a line of Rust or Go but both look more compelling.


Because everyone who could make that change already switched to Java, Python, and other options instead.


Serious question, if you were going to replace C++, why choose D over something like Ada?


Without going into the language details: it seems there is only one open-source free compiler for Ada, while there are three for D.


Facebook uses D internally.


Most times the reason people switch from thing A to thing B is because they have a problem with A. Nobody has a problem with C++. Talk to any C++ dev, they love their job.


A long time ago, I did C++ dev for about 5 years. Absolutely hated it. Part of that could have been that it was C++ for Windows, but even so...

Slow compile times, a sea of compiler options, pragmas, swamps of macros and templates, and the complete lack of understanding among coworkers of OO concepts like virtual functions or inheritance.

Can totally sympathize with Linus' contempt for C++.

edit: Notice dingo_bat is getting downvoted on this. How about responding with why you dislike C++ instead of the downvote?


If you use C++ as "C with Classes", it is a fantastic C replacement.

Just stick to 'struct's instead of 'class'es, use ctor/dtor for RAII, pure virtual functions to declare interfaces and single-level inheritance to implement them and, perhaps, an occasional template to replace a macro - and you still basically have C, but it's now far less verbose and more pleasant to use.


Fair enough, but how many train wrecks did you have to witness to come to that conclusion?


Hehe... in my case there was some oscillation between C and C++ before eventually converging to C-style C++. To each his own. I even heard of people who thought Boost was a good thing, but I suspect someone was making a joke.


Boost is being surpassed by new standards though. Most of the truly and widely useful stuff from boost is being reimplemented in a much cleaner way for standard library. It can be considered proving ground.


But C doesn't have virtual functions or inheritance either.


Which isn't that much of a problem. When that approach is truly called for, you can fake it well enough in C with function pointers and macros. I know that isn't easy. If it makes you think first, sometimes "not easy" is a net positive. With "easy" OOP, the typical result was a wad of tightly-coupled classes that were difficult to enhance or reuse.

C++ jammed so many different concepts into the built-ins, catering to all yet pleasing none. Last I checked, exceptions were still kind of a mess. Places I know that still use it have their own peculiar commandments as to what is halal and what is haraam. I do not blame them.


This I find disagreeable. I love C++ but I've never considered it more than a love hate relationship. Like I believe Bjarne has said, there's an elegant language hiding inside of C++; the problem is, though, that this elegant language is Not C++.

Most C++ code I've ever written has at least had some issues with memory or threading, even with the best discipline I've had with C++. I think this is an experience many people share and probably a reason why a lot of folks are so excited for memory-safe alternatives like Rust.


Not to mention that there’s huge C++ codebases out there (gaming, financial industries etc.) Great C++ skills will still be in demand for quite a while. Trying to ramp up new developers on a new, “too-bleeding edge” language/framework is too expensive. D markets themselves too hard on the C++ crowd, whereas languages like Rust and Go market themselves well outside the C++ circle to bring those devs closer to something that they can use as part of a performant service imo. I like D, but I think the two other languages stole the spotlight here.


I like D. I learned all the things in D I could never really understand when I tried to learn about them in C and C++. Things like pointers, structs, unions the different sizes of types and other things. It's the first language that really made me appreciate why static typing and memory management are useful and why you can do things in a lower level language you can't do in a higher level one. But i also found the syntax fairly easy to pick up, I could never really wrap my head around C++'s weirdness, and my little bit of C knowledge made it fairly easy to begin learning more complicated aspects of the language. I have to admit some parts of it confuse me a bit. I still don't fully understand Templates and ranges but i've used them a little bit and can see why they're useful. I like the dub build system and code repository and definitely prefer imports to #include.

As far as a lack of ide's goes. There isn't many. I like dlang ide. It has everything I need, though it can be kind of buggy. I also don't mind Vim with dlang plugins. But I don't think they can compare to large established ides for other languages.

I can also understand why it doesn't really pick up for large projects the way c++ is.

There isn't much in the way of libraries, there is no tutorials or help aimed towards beginner programmers, which is too bad because I think D is way better for beginners than Java or C, it teaches the same important concepts as both languages while providing a fairly strict compile time checking and a far less ridiculous syntax than java. With the option to not have to learn OOP stuff until you understand basic programming. It also makes it a lot harder to shoot yourself in the face the way C does.

The standard library docs and most other documentation I've seen for D is fairly technical and not very inviting even for non beginners. Most libraries have little to no documentation and many haven't been maintained.

The only real, understandable learning resource I could find is:

http://ddili.org/ders/d.en/

Which is a great book, but also nearly the only readily available one to learn from.

It is too bad because there are definitely lots of benefits to C++ it's just they're not quite worth the tradeoffs.


> I think D is way better for beginners than Java or C

I love D but tbh I disagree. I think an optimal-ish progression for learning programming languages is:

Python (basic programming&computer knowledge, algorithms) -> C (low-level knowledge) -> ASM (optional, only if you want to learn extra low level knowledge) -> C++ or Java (to learn modern OOP concepts. D's are a bit too complex and the error messages aren't as good and thus off-putting to a beginner) -> D (amazeballs metaprogramming) -> LISP (amazeballs metaprogramming and FP)

Neither C, D, nor Java should be beginner languages. They're too big and fancy. (To be fair, python does this too, but it does a bit better job of hiding it, and exposes an api that can be leveraged to teach people programming even if they don't understand how it works.)


C should never be learned on the path of being a good, programming safe conscious C++ programmer.

CppCon 2015: Kate Gregory “Stop Teaching C"

https://www.youtube.com/watch?v=YnWhqhNdYyk


C should ALWAYS be learned on the path of being a good, programming safe conscious programmer of ANY language. Otherwise you will not understand the underlying machine.


C is not the only way to understand the underlying machine, plenty of languages offer similar features.

Plus being a subset of C++, there is hardly any value in learning C as such, instead of good C++ idioms.

In fact, my university already in the mid-90's never teached C, only C++ with a professor that was insightfull to have its own set of type safe abstractions, the usual array/string/containers set, while teaching us about RAII, years before C++98 and STL were a standard.

There were system programming assignments in C, it was expected that any student would be able to think and know how to apply C++'s C subset for the assignment.


> Plus being a subset of C++, there is hardly any value in learning C as such, instead of good C++ idioms

To say this is to miss the point entirely. A machine runs not C++, but C. To learn how to use, e.g., std::vector (to cite a random example) is to learn a high-level programming concept which could be learned in any language but not to learn how the machine works. To learn how to use a char* in c++ is a complete waste and not different from learning how to use a char* in c.


No, you are the one missing the point.

CPUs don't run C, and unless we are speaking about a PDP-11, the ANSI C abstract machine surely doesn't expose how this mobile phone CPU/GPGPU works.

When I want people to actually know how computers work, I teach them Assembly.

C isn't a special snowflake in the realm of systems programming languages, there are plenty of languages, some even older than C with the same low level capabilities.

Had AT&T been allowed to sell UNIX at the same price the as other OS vendors were selling their products instead of giving it almost for free to US universities, we wouldn't be talking about C nowadays, and probably also not about C++.


> C isn't a special snowflake in the realm of systems programming languages, there are plenty of languages

That's just not true. You see something like assembly, which seems so low-level and implementation-focused, and then you see java with all its high-level complexity and it seems like it's fundamentally something different. C bridges that gap, because you can see all the ways in which it's exactly the same as assembly, yet all the ways in which it's exactly the same as java. If you truely want to understand a computer on every level from silicon to state-machines (idk, it was the first thing that came to mind), C belongs on that stack.

What makes c special is not its capabilities, but rather its lack of abstraction.


Ok maybe not beginner. I was thinking more of a second or third language I suppose. I'm mostly self taught other than some BASIC classes in highschool and a bit of R for statistics in university. I never really understood most of the concepts of programming from that. I've tried to learn a bunch of languages on my own. For some reason I tried to start with perl and around the same time C....I wrote a few things but I got stuck on structs with C and well...perl...with perl so I gave up on those. I tried python and couldn't stand it. Tried c++ and D1 and got about as far as I did with C. At the same time I was reading general programming books and looking at lisp and scheme like they used in the books but I just didn't understand them at all...but I sort of understood the idea of functional programming and had understood enough of C to get how cool it was to be able to have fumctions return other functions and the ability to have anonymous functions.

In the end I ended up learning lua as my first real language where I finally knew how to use programming to make things. I experimented with a few functional programs in lua and learned enough about OOP and luas metaprogramming to design my own classes and start working on some small games and bigger projects.

Eventually I started to run into lua's limitations (every number is a floating point number, the classes I designed couldn't be serialized properly, there wasn't really a way to debug a lua program, lua's tables and metatables are kind of weird) and most of the answers I looked at pointed to needing to understand C and use lua's c bridge to get the kind of functionality I wanted from lua.

That was when I rediscovered D and all the things that confused me about it before just made sense this time. I have been also trying to learn C along side it just because it seems like it's something I should know. But I've been writing most of my stuff in D lately, even smaller programs just because I find it has the balance between lower level and higher level stuff I need and can use for what I know.




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

Search: