Style Guide

For consistency, we enforce some style guidelines with ClangFormat and Clang-Tidy. These are defined in the .clang-format and .clang-tidy files.

Here are some conventions to follow:

  1. All SPADES specific code must be within spades namespace.

  2. Following AMReX convention, header files will use a .H extension and C++ source files will use a .cpp extension.

  3. Use snake_case almost everywhere, i.e., for variables, namespaces, function and method names. Exceptions include when overriding AMReX class methods in inherited classes.

  4. Use CamelCase for class names. Capitalize the first letter of the first word in the compound name also.

  5. Use m_ prefix for class instance variables. No prefix for class methods.

  6. Keep logic in functions short. Always use descriptive names for function names and variables that provide the reader with clues as to what the function does.

Formatting

This is a manual way to format all source files:

$ cd Source
$ find . \( -name "*.cpp" -o -name "*.H" \) -exec clang-format -i {} +

Linting

Linting of SPADES can be performed using cmake options to configure cppcheck and clang-tidy. For example, the continuous integration tools through Github Actions uses the following for clang-tidy:

$ cmake -DCMAKE_BUILD_TYPE:STRING=Debug \
        -DCMAKE_CXX_COMPILER:STRING=clang++ \
        -DCMAKE_C_COMPILER:STRING=clang \
        -DSPADES_DIM:STRING=3 \
        -DSPADES_ENABLE_MPI:BOOL=OFF \
        -DSPADES_TEST_WITH_FCOMPARE:BOOL=OFF \
        -DSPADES_ENABLE_ALL_WARNINGS:BOOL=ON \
        -DSPADES_ENABLE_CPPCHECK:BOOL=OFF \
        -DSPADES_ENABLE_CLANG_TIDY:BOOL=ON \
        ..
$ cmake --build . | tee -a clang-tidy-full-report.txt

A code spellchecker can be run by running codespell in the project directory.