I have a research project with several files (~100). The code has been written over the years without any specific style. Each developer (mostly master students that come, code and leave) used their own "style", if any.
Now, I'm trying to maintain the code in a way to make new people that join us follow certain rules. I found that Google published some style-guide. Luckily enough they published also a python script, that is easy to use.
The problem is, the script gives me for each file a tone of silly errors like
Missing space after , [whitespace/comma] [3]
or
Missing space before { [whitespace/braces] [5]
My question is: Is it somehow possible to automatize the correction of such "errors"? That mean running a script over a file that eliminates automatically all those errors.
It was vetted for being useful at the time when it was introduced. Many parts of C++ are very old and what was considered useful at the time might be a bad idea nowadays, either because better alternatives exist, or because it turned out that the feature has flaws.
A decent rule of thumb is to not inline a function if it is more than 10 lines long. Beware of destructors, which are often longer than they appear because of implicit member- and base-destructor calls!
Starting in Visual Studio 2022, the C++ Linter is enabled by default. To use it, just open a source file in the editor. The linter shows any problems it finds by annotations in the editor window and in the Error List window. In Visual Studio 2019, the C++ linter is available as an option.
Common guidelines for C and C++ codeDo not use leading underscores, as all such names are reserved according to the C/C++ standard. Name include guards like GMX_DIRNAME_HEADERNAME_H . Boolean variables are always named with a b prefix, followed by a CamelCase name. Enum values are named with an e prefix.
clang-format
might be useful, as it can be run with an option to use Google style rules:
clang-format -style=Google ...
See e.g. http://clang.llvm.org/docs/ClangFormatStyleOptions.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With