My Love-Hate Relationship With C++

C++ No Comments »

I have quite a love/hate relationship with C++. Put simply, I love C++ because no other language allows you to both create very high-level programming abstractions along with providing you the ability to have extremely fine-grained control when you need it. I hate C++ because it is so complicated and riddled with so many “gotchas” and “dusty corners” that it makes me wonder how any programmer, myself included, can safely wade through the minefield.

If you think you know C++ well, I challenge you to read Exceptional C++1 by Herb Sutter; I guarantee it will raise subtle issue after subtle issue that you have never considered before. For example, do you know:

  • … why you should list members in an initialization list in the order in which they are declared?
  • … why you should prefer preincrement (++i) to postincrement (i++) whenever possible?
  • … the different levels of exception safety, and how to write functions and methods which provide these levels of exception safety?
  • … the “canonical” fully exception-safe form of copy assignment implemented almost entirely in terms of the copy constructor?
  • … that if your copy assignment operator requires if (this != &other) for correctness it is almost certainly not fully exception-safe?
  • … why you should avoid implicit conversion operators and prefer marking constructors explicit whenever possible?
  • … the compiler-firewall (Pimpl) and “fast Pimpl” idioms?
  • … when you should use private or protected inheritence?
  • … how to minimize compile-time dependencies in header files to speed up compilation?
  • … the many subtleties of Koenig lookup?
  • … why the bool type needs to be builtin and can’t be properly emulated?

Because I found Exceptional C++ so interesting (and so challenging), I ordered its sequel, More Exceptional C++2.

[1] Sutter, Herb. Exceptional C++. Boston: Addison-Wesley Professional, 2000.
[2] Sutter, Herb. More Exceptional C++. Boston: Addison-Wesley Professional, 2001.
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in