On the richness of C++

Sean Kelly sean at invisibleduck.org
Thu Apr 10 12:21:09 PDT 2008


== Quote from Georg Wrede (georg at nospam.org)'s article
> I read
> http://www.nwcpp.org/Downloads/2007/redcode_-_updated.pdf
> and upon reading it I got thinking of something else. Those familiar
> with C++ (aren't we all?) probably sometimes come across things that
> somebody has done in C++ that are simply stunning. Things that one would
> have thought would need a new language, or maybe just be impossible to
> implement at all. I know I have. (A lot of Boost stuff is like that,
> originally the STL got me breathless, but there's a lot that's not
> template related, too.)
> Is it just paranoia, or is C++ still more flexible and expressive than D?
> Are there still things you can do in C++ that are impossible or too
> awkward to do in D?

I think one could argue that the current implementation of mixins is a
weak replacement for multiple inheritance, and that this makes certain
design patterns a bit less pleasant in D than they would be in C++.  Also,
the lack of ADL in D can be frustrating at times, though D 2.0's overload
groups may address this issue.  In fact, it's overload groups and struct
ctors that has me wanting to move to D 2.0.

> Of course, I don't mean Obfuscated C(++). While that definitely
> demonstrates the unfathomable agility of the language, I'm only talking
> about serious, non-juvenile stuff.

As far a template metaprogramming is concerned, while a great deal is
possible in C++ (as Boost shows), the syntax is such that I don't actually
support the idea of using it for anything sufficiently non-trivial.  While
I feel that metaprogramming is conceptually very straightforward, actually
using it to the degree suggested in modern literature tends to render the
resulting program incomprehensible and unmaintainable by the vast bulk
of C++ programmers.  Thus I feel the issue often isn't implementing
something fancy so much as making it sufficiently elegant that it's
practically usable.

Another issue with template metaprogramming is that there is precious little
literature on the topic.  Andrei's book uses it a great deal, but the only C++
book I know of that actually describes common constructs is "Generative
Programming," which few people seem to have read.  I'll admit that this was
one motivating factor for my covering it in our book on D--I was hoping to
make template metaprogramming seem a bit more understandable and at
the same time show how much cleaner the D syntax is for this sort of thing.

It's perhaps worth mentioning as well that between string mixins and CTFE,
D is light years ahead of C++ in terms of metaprogramming.  This is one
area where it's fairly easy to render code completely impenetrable, but it
can be quite elegant if used correctly.  And CTFE is a good companion for
template metaprogramming in that each have their respective strengths.


Sean



More information about the Digitalmars-d mailing list