Homogeneize formatting in the C++ code
The c++ code has become a little bit disorderd due that each one of the developers is more fund to a particular coding style. For example, there are several parts of the code that use tabs instead of spaces. Another places the intentantion is 2 spaces instead of 4. The opening of the braces of
if-else conditions and
for-loops is sometimes done in the same line and sometimes in the next one, and etc. There is no big issue with each one of these inconsistencies, but in the end, they sum up and make our code look somehow disorganized.
Use automatic tools to ensure that we follow a consistent format scheme through the code.
clang-format is available in many systems and can automatically apply specific formatting options. Then, the idea is to agree in a specific format and to store it in the repository with the file
.clang-format so that is clear that we follow it.
I personally use plain Mozilla settings with the Mozilla coding style because is the one most similar to the style used in dune. But I am open to any other proposal.
Once decided upon specific settings, we should use the tool once over the whole repository to make existing code follow the new format.
New code may not follow the format we choose for dorie. Hence, I see two ways to enforce new code to follow these rules:
- Allow any format in merge request and pass
clang-formatevery now and then.
- Do not accept merge requests without the appropiated format.
The first one is relatively easy to apply for every one but will clutter our git history. The second is more drastic but could be more easily enforced by providing the right tools for it. For example, by providing a git hook that checks and applies the format settings. In the second case, we would have to update our contributing guide.
EDIT: Correction on the link to the git hook: https://github.com/barisione/clang-format-hooks