Enforce consistent C++ naming conventions
What has to be done
Currently our code uses a bunch of inconsistent naming conventions - there's a mixture of like_this, likeThis, LikeThis and Like_this for class/type names, functions, parameters, variables and constants.
We should enable build-time checks that enforce some useful set of naming conventions. Per personal communication with Martin, basing it on the Google style guide is okay.
This issue can be closed when ./test.sh includes running a configurable set of naming enforcements.
How do you know it has to be done
- Consistent naming would reduce the burden of choosing a naming style for new code people write.
- Confirmed that this is a useful thing to do in this Software team meeting
Code pointers
Most likely we should do this as just another clang-tidy check (https://github.com/RespiraWorks/VentilatorSoftware/issues/132)
I'm personally partial to the google style guide: CamelCase for classes and like_this for variables, etc.. I'm guessing you might be familiar with this convention? :)
Yeah, following Google style guide is a reasonable default choice and I am indeed familiar with it :)
For somebody who decides to take on this issue: it can be done incrementally e.g. in the following steps:
- Establish the enforcement infra but with an empty set of rules
- One by one add naming enforcements e.g. for files (forgot to mention that our files are also inconsistently named), functions, classes etc, coupled with fixes of that entity in the same commit
This would generate commits that are not quite as huge and tedious to author as one giant commit bringing all the code in compliance with everything.
Another approach, perhaps even better, is to first gradually bring things in compliance, and then add the tool enforcement + rules in the same commit with final fixups.
I'm gonna try to take this one and enable clang-tidy while we're at it, as clang-tidy supports enforcement of naming conventions too.
@jkff do you still intend to work on this or shall we untag you and keep this open for newbies or something?
Yeah unfortunately I don't have time work on RespiraWorks these days - untagged myself. All the best to y'all!
Just taking notes on the progress here.
Looks like you have to sudo apt install clang-format
I have tried this:
git clang-format --extensions cpp,hpp --style=google -v
but it seems to only fix whitespace and not variable naming conventions
Just taking notes on the progress here. Looks like you have to
sudo apt install clang-formatI have tried this:git clang-format --extensions cpp,hpp --style=google -vbut it seems to only fix whitespace and not variable naming conventions
Apparently clang-tidy can enforce naming conventions. I've not used this feature yet, but the documentation is here: https://clang.llvm.org/extra/clang-tidy/checks/readability-identifier-naming.html
I don't see predefined style options (ex,--style=google) for clang-tidy.
Looks like this is what we are looking for: https://gist.github.com/airglow923/1fa3bda42f2b193920d7f46ee8345e04