Why D kicks serious ass over C++, leaving it dead and broken on the sidewalk
boscoh.com
boscoh.com
That kind of scares me. Who cares how hard the compiler writer's job is? A compiler is written once, whereas the programs that the compiler compiles (hopefully) comprise a much larger body of code.
That said, the article sure made D sound like an improvement over C++, with many of the same benefits. Of course, getting rid of the preprocessor seems kind of strange... I've used quite a few macros in my C code. Even the crappy macros you get with C (as compared to, say, Lisp) are certainly better than none at all.
Based on features such as the ability to write source code in 6 different character formats, it doesn't seem like the sort of features he's talking about imply sacrificing anything in the language.
It probably means things like this (http://www.digitalmars.com/d/lex.html)
Complex literals are not tokens, but are assembled from real and imaginary expressions in the semantic analysis:
4.5 + 6.2i // complex number
Stuff that is invisible to a programmer. (This was a completely random example, I don't know whether it's really such an optimization or not.)One reason to make a compiler easy to write is that it makes the language more portable, which is an important feature of a low-level systems language. Low level languages are more difficult to make portable. One of the reasons the original C was so successful is that it was (relatively) easy to implement a compiler for your architecture.
I think one of the best reasons still to use c++ is your control over memory and the speed which you can only get when allocating objects on the stack. Maybe that was the sort of problem he was fighting with in c++, but for me it's an argument which would make D a worse choice than c++ for those tasks where I would use c++ now.
Those who try to fix C/C++ with a "nicer" declaration syntax always fail unless they just copy C/C++. So what's so special about C-style declarations?
int a[10];
vs. int[] a;
The first is more natural, since you are going to apply the index operator [] to a later on, many times. This is purely psychological. This shows that our understanding of "regularity" and "relevance" of a formal syntax may be against our instincts.So, for example, you can't do this:
int a[10];
int b[10];
a=b;
You get a type error, or an lvalue error, because you can't assign anything to a constant.My main point is that this is a relatively cosmetic issue relative to the ability to use 'foreach' syntax instead of iterator objects and while loops.
There's clearly a market for some sort of a fixed C++ but not the Java/C# way. D tries to fill the niche, but it doesn't give a feeling of elegance or otherwise of something really new and unseen before.
But there are other things as well like the lazy evaluation, and built in contract and unit test support.
Ave a look at the articles on this page http://www.digitalmars.com/d/
And the specifications http://www.digitalmars.com/d/lex.html
Variadic templates: can be done with variant arrays and again, with smart compile-time evaluation if necessary.
No wonder there are so many useful applications written on D!