may contain source code

published: • tags:

Three and a half years ago I wrote down my personal C++ Coding Guide. My programming style has changed a bit since then, and it’s time for an update of the original article.

This is the changelog:

  • The clang-format style definition was created for … not sure exactly. Clang 6? I updated it for Clang 15. Nothing substantial changed.
  • The name of the private namespace changed from detail to private_. On the one hand detail is extremely common in the Standard adjacent community. On the other hand I’ve had collegues ask about the meaning of the name. And they do have a point. That detail is short hand for implementation detail isn’t that obvious on first glance. I’m hoping private_ has a strong enough connection to the private keyword to not cause any doubts about its meaning.
  • When anonymous namespaces grow it can get a bit confusing whether a particular function is in such a namespace or not. That’s why I’m slowly changing to using static instead more often. The guide now mentions both possibilities.
  • Template parameter naming changed. The old guide’s language around single letter names was too strict. Also, it mandated suffixing type paramters with a T. Interestingly, it contained no mention of a suffix for non-type parameters. In practice I use T and _v prefixes, but only for disambiguation when creating aliases.
  • Removed the section about not exposing the internal state of a class for direct mutation. While being great advice, it’s not specific to my programming style. General C++ best practices are out of scope of the guide.