Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the main differences between C++, D and C++0x? [closed]

Tags:

c++

c++11

d

We all encounter and hear them more often lately and i'd like some good comparison between them right here on stackoverflow. Links, references and articles are fine also.

like image 764
Shinnok Avatar asked Jan 01 '11 20:01

Shinnok


3 Answers

C++0x is definitely more like D than C++ 98 or 03 is, but they're still definitely different languages. Stereotypically, D is viewed as a better C++, and it is more like C++ than any other language, but it's still very much its own beast. That being the case, the only feature that I can think of off the top of my head that C++ has which D definitely lacks is multiple inheritance, but given all of the problems with multiple inheritance, pretty much every language after C++ has decided against it. Instead, D introduces a number of other features such as alias this and mixins to allow for implementation inheritance (on top of having interfaces like C# and Java), so you can generally still get the benefits of multiple inheritance without all of the headaches. There are probably some other things that C++ has that D doesn't, but you're likely going to have to search hard for them.

D generally can do anything that C++ can do, but it can do more than C++ can, and it can often do it better. D's weaknesses lie primarily in its relatively young compiler implementation (which can mean bugs in the compiler when dealing with newer features) and the fact that its standard library is very much a work in progress (though much of what's there is fantastic, and it continues to improve and grow). However, given time, those problems will obviously go away. If anything, I'd say that D is quite a bit more powerful than C++. I find it frustrating when having to program in C++ after having done a bunch of programming in D. That's particulary true when it comes to templates (D's templates blow C++'s templates clear out of the water in terms of power and useability). Generally-speaking, D is just plain more powerful and less error-prone. The problems that it does have are implementation issues which are completely temporary and which are steadily being fixed.

Now, as for C++0x, it's adding a number of new features to C++ which are definitely going to improve it. Some of those features are already in D. Some examples of that would be lambdas, foreach loops, and auto (I'm particularly looking forward to auto. I've been quite suprised at how big a game changer it's been in D). So, some of the things that D improved on over C++ 98/03 are going to be in C++0x. But obviously not all of them will, and C++ is definitely a different language than D. It isn't D. It can't be D. And it shouldn't be D. While they are very similar at the core, they are definitely different languages.

If you really want to know more about D, you should check out Andrei Alexandrescu's The D Programming Language, which is the definitive book on D and one of the best programming books that I've ever read. Also, as pointed out in another answer, there is a fairly good comparison grid of various languages here. And, of course, there's the official site.

like image 188
Jonathan M Davis Avatar answered Sep 22 '22 04:09

Jonathan M Davis


I used to be a C# programmer (I know C++ and Java too), but after learning D, I'd say that it would be the best language ever, if only its compiler was bug-free. Just look at these pages:

Languages versus D

D Language Features

There's two main reasons D hasn't caught on:

  1. The compiler isn't bug-free (e.g. forward-reference errors are very annoying and a pain to solve) (Edit: it's improved a lot!).

  2. There's no portable way to interact with legacy C++ code with pretty much any other language, including D. Hence most people are just forced to continue using C++ to be able to use their old code.

  3. While using the GC isn't "required", the standard library uses it extensively, so you're pretty much forced to use it if you're using Phobos. There are plans to fix this, I think, but as long as this is the case, people who want manual memory management will probably avoid D.

If those problems were solved, I'd say that D would probably catch on pretty rapidly.

like image 35
user541686 Avatar answered Sep 20 '22 04:09

user541686


My experience is mostly that C++0x tweaks certain aspects of C++, but essentially, it's the same language, just cleaner and somewhat more flexible. However, there are plenty of the major problems left in C++0x, like #include, and the automatic type deduction code for regular functions doesn't go far enough by quite some way. I like C++0x, it's a great improvement, but it's a small step in the right direction.

D, I found to be, well. I dunno. I didn't like D. I felt that it didn't fix the problems that needed fixing in C++, and pretty much went it's own way. I mean, there's nothing wrong with a language being whatever it wants to be, but it didn't feel to me like D genuinely evolved on C++, it's just a C++/C# hybrid and is only as much an evolution as C# is. For example, it has the same single-root object hierarchy, enforced GC, etc. It felt to me that D could be C# with some features like generics and RTCG just moved to compile-time instead of run-time.

C++0x doesn't go far enough and D wandered way off to the side into a field where C# and Java already exist. I'm definitely still in the market for something else as a C++ successor.

like image 26
Puppy Avatar answered Sep 24 '22 04:09

Puppy