Reference implementation to review/discuss
This is primarily the start of a long process to evaluate how to simplify the
burden of code formatting styles. The goal is to have at least one tool that can automatically
enforce the desired style.
Benefits of choosing clang-format is that the tool:
- is robust (does not introduce compiler errors),
- is integrated with many IDE’s/Editors
- https://clang.llvm.org/docs/ClangFormat.html, https://github.com/rhysd/vim-clang-format
- is used by many other tools
Considerations to be aware of
- the whitesmith style of indentation is not supported by clang-format or any of the common style guides used by recent open source projects. This implies that the bracket indentations will need to change (similar to VTK’s change a few years ago).
- clang-format parses the code (making the tool robust), but then generates the formatted code from the parsed representation. This means that the formatting is for the entire rule set, not just one rule at a time.
I have recently started to convert to using automated strict formatting conventions, ONLY IF THE STRICT RULES can be fully automated. A flexible choice that requires manual decisions, in my opinion, is less effective than strict rules that can be widely automated.
I have been partially converted based on the doctrine espoused by the python “Black” (https://github.com/python/black) formatting tool. Since submitting to “Black” as the authority for formatting in python, and allowing my editors to auto enforce that style, I find that I am saving a lot of time doing house cleaning. I can write python code as a stream-of-algorithmic-conciousness, press [File][Save], and Black reformats the code as needed for style and future readability. I LOVE IT!
Now… The trick is finding tools, and providing documentation, that can be widely automated. CLion, Visual studio, vim, emacs all have plugins that automate compliance by relying on clang-format. I’m working on that this summer. I think I have a “clang-format” based solution that will be no more difficult than the “kwstyle” tests.