Inherent code performance advantages of D over C?

H. S. Teoh hsteoh at
Tue Dec 10 07:33:26 PST 2013

On Tue, Dec 10, 2013 at 10:38:42AM +0100, Joseph Rushton Wakeling wrote:
> On 10/12/13 09:21, H. S. Teoh wrote:
> >It turned out that I had overlooked a simple but very significant
> >optimization present in the C version that hadn't been implemented
> >in the D version yet. [...] In the original C code, it took quite
> >a while to implement this optimization because ...  well, in C, you
> >had to spell out every last thing, otherwise it just won't work. In
> >D, I kicked a crude version of it out in under a day.
> There are such amazing multiplicative gains from D's design
> decisions -- as you describe here, even when you _need_ to drill
> down and micro-optimize, very often that too can be achieved in a
> way that is simpler than its C equivalent.  And so, at every level
> of your code, you get that opportunity to focus more on exploration
> and improvement and less on firefighting.

I like that term "firefighting". :) An apt description of a large
proportion of C programming. And I would add, *especially* true in C++
(cf. At a certain
point, it just becomes so tiresome to be spending more time fighting the
language than actually attacking the problem you're trying to solve.

That's not to say everything is perfect in D -- sometimes working around
compiler bugs (or issues in the const system) starts to feel a bit like
firefighting too.

But D gets so many more things right, that I find myself far more
productive in D than in C or C++. Exploration is far easier, as you say.
Especially in C, the lack of adequate abstraction mechanisms force you
to commit to a particular design early, and once you commit to that
design, it takes a major overhaul if later on you decide that a
different design is better. A lot of time is spent fighting the
language, rather than actually moving on with the task at hand. I would
say this is another point where D wins over C: sure, if you already know
exactly how your final program will look like, you can plan ahead and
design it for maximum performance from the get-go in C.  But many times
you *don't* know beforehand what's the best design, and there's quite a
bit of exploration needed before you settle on one. In C, exploration is
difficult because it could mean rewriting the whole thing from ground
up. In D, far less effort is needed, which gives you more time to work
on stability and tuning performance, rather than throwing in a bunch of
last-minute hacks just to make things work because you've spent too much
time firefighting, and now the deadline's almost up and the product
needs to be shipped.


This is not a sentence.

More information about the Digitalmars-d mailing list