Currently our C++ style guide (https://developer.lsst.io/coding/cpp_style_guide.html) has lots of rules relating to formatting. Following these rules consistently takes time. When it is not done consistently the code looks different resulting in a higher cognitive load when reading. Moreover, digesting and the style guide itself also costs time.
In other languages (namely Go) it is common practice to let a tool (e.g. gofmt
) handle all code formatting. From my own experience I can say this is extremely convenient. All code will always automatically be formatted exactly the same, and complying with the standards costs zero time. It can even be integrated with an editor save hook to automatically run the formatter when saving a file. This allows you to not worry at all about things like indentation, include ordering, etc.
For C++ the clang-format
(http://clang.llvm.org/docs/ClangFormat.html) tool enables this for C++. It has standardized profiles complying with the LLVM, Google and Mozilla coding styles and a flexible configuration system (http://clang.llvm.org/docs/ClangFormatStyleOptions.html) to further specialize those styles. If more control is required the libformat
offers that as well.
I would like to suggest that we use this tool to format all our C++ code. Following the recent change of the Python style guide to be a diff against PEP8, the C++ style guide can then just be a diff against whichever style we adopt for clang-format
.
Based on the feedback here I would like to RFC this suggestion.