Tags C & C++

As I skim through Alexandrescu's "Modern C++ design", I experience a mixture of fun and terror.

The book is considered one of (if not the) most advanced book on C++ out there. It describes progressive generic programming techniques and design patterns, using the C++ language.

In the preface it says that the author is "displaying extraordinary creativity and programming virtuosity". By these, they mean stunning hacks, that IMHO just bridge over the imperfections of C++ to create some very complicated designs.

For instance, you want to check that some type (say foo) is larger than some other type (say bar), during compile-time. How do you do it ?

#define STATIC_CHECK(expr) { char unnamed[(expr) ? 1 : 0];}


STATIC_CHECK(sizeof(foo) <= sizeof(bar));

This uses the fact that zero sized arrays are illegal in C++ and the compiler will throw an error if the condition isn't true. While this is definitely a hack to brag about, I just feel I want to scream "FFS, does it have to be so hard !!!!".

If you want customizable "smart pointers", no problems !! The author has an implementation for you, and it's very "simple" too - it uses a host of design patterns, templates of templates, with partial specialization and defaults, and a few hacks as "pretty" as the one described above. And all this for what purpose ? To compensate for C++'s lack of memory management ? Well, thank you.

Don't get me wrong, I like C++. It's a powerful and efficient language, and I use it regularly. But I sometimes wonder - do things need to be so complicated ? Isn't there an easier way ??

This all reminds me of a quote by Paul Graham in his article "Why isn't Arc especially object-oriented":

Object-oriented programming is popular in big companies, because it suits the way they write software. At big companies, software tends to be written by large (and frequently changing) teams of mediocre programmers. Object-oriented programming imposes a discipline on these programmers that prevents any one of them from doing too much damage. The price is that the resulting code is bloated with protocols and full of duplication. This is not too high a price for big companies, because their software is probably going to be bloated and full of duplication anyway.


comments powered by Disqus