We all encounter and hear 开发者_如何学JAVAthem more often lately and i'd like some good comparison between them right here on stackoverflow. Links, references and articles are fine also.
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.
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:
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!).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.
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.
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.
D is a different language, supposedly invented to solve a lot of issues with C++. I've never tried it because I wasn't ever bothered by C++'s "issues".
C++0x is a new standard for C++ that adds a lot of much needed features (not all we'd hoped for unfortunately though). To see what C++0x adds, have a look at the wiki entry on it:
http://en.wikipedia.org/wiki/C%2B%2B0x
C++0x is the next standard of C++ (the previous of which was set in 2003). The two are one single language.
D is a whole other language. You might better ask what are the commonalities between C++ and D. I have approximately zero experience with D so I can't tell you my view on it, but I do have quite a bit of experience with C++. I've heard that one of the most significant (supposed) issues with C++ that D solves is garbage collection: C++ doesn't have a garbage collector while D does have one.
I personally like it C++'s way much better. I know little about garbage collectors, but last time I checked there was no efficient garbage collector in existence which guarantees correct and deterministic memory clean-up, with regard to exactly when the GC bursts in and does its stuff. Granted, dynamic allocation in C++ can fail, but there are ways to group all of the program's memory allocation failures to one point (a memory pool), such that you can tell at compile-time that once you pass that point there shall be no failures by operator new
. This technique also gives you nearly-instant dynamic allocations: allocations are then internal to the program and are a mere game of pointers.
Also, garbage collectors only apply for memory, not other resources.
Just trying to provide a simple summary answer:
C++ is an imperative, multi-paradigm programming language. C++ until recently provided no primitives for concurrency, and programmers relied heavily on library support. C++ supports complex multiple inheritance. The C++ standard includes an extensive standard library.
C++0x As of writing (2-Jan-2011) C++0x is the latest draft standard of C++. It adds many new features that help to bring it inline with other modern languages. Some of the more notable features include: concurrency and threading features, lambda expressions and extensions the existing meta-programming support.
D is a separate language heavily influenced by C++. It borrows concepts from Java and Eiffel. D implements garbage collection. D has replaced C++ multiple inheritance with interfaces and mix-ins support.
C++ and D have completely different standard library implementations. C++ has gained wide industry acceptance and is commonly used. D has failed to penetrate the industry to the same degree.
精彩评论