Unclear about the benefits of D over C++ and Java

Guillaume Piolat via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 2 05:08:10 PST 2016


On Saturday, 2 January 2016 at 11:31:24 UTC, Dibyendu Majumdar 
wrote:
> Hi,
>
> I am a long time observer of D but have never done any coding 
> in D. I have considered using D several times but have ended up 
> either going with C++ or Java.
>
> I feel that for someone like me it is not clear what 
> significant advantages D has over C++ or Java to make a switch. 
> I cannot afford to experiment with a language unless I know for 
> certain the benefits of using it.
>
> For instance I would like to know:
>
> * Do D compilers generate more efficient code compared to C++ 
> compilers? Are there performance benchmarks comparing D 
> implementation against C and C++?

Same efficiency if using LDC or GDC, divided by 2 if you use DMD.
But I've found coding in D is more productive (I'd say 2x on 
small projects vs C++, correct me if you disagree) and you'll be 
more pleased with the results so you'll have more time and energy 
to optimize.
C++ has some overhead to create a program so it may lead you to 
tool less.

> * Can D generics do everything C++ templates can (are they 
> Turing complete for instance) - and what additional 
> capabilities does D have that would make a significant 
> difference to the way templates are used in C++?

The difference is mainly in community, most are very confident 
with meta-programming, it's not up to single individual in a team 
to explain static polymorphism to everyone.

To put bluntly, I've never seen a C++ programmer in a team use 
std::enable_if in years of C++, but every D programmer has 
written heaps of "static if".
D lets you use static or runtime polymorphism as easily, in C++ 
it's quite a learning and often people think they don't need it.

That said, it's not all community, there is tangible 
improvements. Syntax for templates, alias this over multiple 
inheritance, string mixin over preprocessor macros, static 
foreach, sane operator overloading and so on.

> * How does D's performance compare with Java when it comes to 
> concurrent applications or garbage collection?

Java have more concurrency primitives and faster garbage 
collection.
OTOH D runtime is smaller.

> * How stable is D? Can one use it without fear that the next 
> version will significantly change the language and therefore 
> one would have to rewrite?

This won't be a problem. Breaking language changes are rare, and 
are easy to fix.

> I feel that the D website could do more to explain why someone 
> should move from C++ or Java to D - and this has to be 
> explained in terms of real world benefits in terms of:
>
> * Performance
> * Quality of implementation
>

Can't speak with anyone else, but for me the real reasons are:
- it's fun
- D says "yes" to everything and is not a Big Idea language
- I'm happier with the results, to the point I want to maintain 
them
- C++ puts you in learning-mode forever. D also does, but without 
you taking notice :)
- I'm hooked and going back to C++ feels horrible, like for many 
people here. We need a D rehab center!

At the language level D improves things in all directions: 
http://p0nce.github.io/d-idioms/#How-does-D-improve-on-C++17?

> For someone like me - cool language features don't count that 
> much unless they lead to real world benefits.

Me too, I care more about shared library support and codegen for 
example than any language feature.

Yet in some cases they do matter. For example default 
initialization brings invisible productivity gains you only see 
when going back to C++.







More information about the Digitalmars-d mailing list