C++ Style Guide

I’m a big believer that any software system should follow a consistent style. The emphasis should almost always be on consistence over justification. In the realm of style, there are a lot of opinions about code indentation, naming conventions, etc. Any of those opinions have some justification, some better than others. However, what makes any of those style decisions powerful is their consistent implementation.

As most programmers have, I’ve struggled with this throughout my coding life. I’ll often come onto projects that follow strange style guides or none at all, and am tempted to start following my own latest preference. However, the best solution is to embrace the strangeness or suggest a move to a different style that is a more commonly accepted standard. But until that suggestion is accepted by a strong majority, embracing the strangeness is the way to go. An example of the style guide I follow these days is the Google C++ Style Guide. They even release an emacs mode for their style (which I haven’t used yet). It is widely accepted across multiple large projects and moreover follows almost all the principles outlined in The Elements of C++ Style that I can tell.

One very cool solution for formatting code in different ways across the whole codebase is Artistic Style. I haven’t used it myself, but it’s highly recommend in a bunch of forums, and is actively maintained at this time.

Leave a Reply

Your email address will not be published. Required fields are marked *