Ventilator icon indicating copy to clipboard operation
Ventilator copied to clipboard

Enforce consistent C++ naming conventions

Open jkff opened this issue 6 years ago • 8 comments

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)

jkff avatar Apr 17 '20 03:04 jkff

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? :)

martukas avatar Apr 17 '20 18:04 martukas

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.

jkff avatar Apr 17 '20 19:04 jkff

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 avatar Apr 18 '20 23:04 jkff

@jkff do you still intend to work on this or shall we untag you and keep this open for newbies or something?

martukas avatar Jul 29 '20 21:07 martukas

Yeah unfortunately I don't have time work on RespiraWorks these days - untagged myself. All the best to y'all!

jkff avatar Jul 29 '20 21:07 jkff

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

martukas avatar Sep 11 '20 18:09 martukas

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

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.

dheater avatar Feb 06 '21 15:02 dheater

Looks like this is what we are looking for: https://gist.github.com/airglow923/1fa3bda42f2b193920d7f46ee8345e04

asmodai27 avatar Apr 17 '21 10:04 asmodai27