Code style¶
All code in fresnel must follow a consistent style to ensure readability. We provide configuration files for linters (specified below) so that developers can automatically validate and format files.
Python¶
Python code in fresnel should follow PEP8 with the following choices:
80 character line widths.
Hang closing brackets.
Break before binary operators.
Tools¶
Linter: flake8 with pep8-naming
Autoformatter: autopep8
Run:
flake8to see a list of violations.See
setup.cfgfor the flake8 configuration (also used by autopep8).
C++/CUDA¶
100 character line width.
Indent only with spaces.
4 spaces per indent level.
Naming conventions:
Namespaces: All lowercase
somenamespaceClass names:
UpperCamelCaseMethods:
lowerCamelCaseMember variables:
m_prefix followed by lowercase with words separated by underscoresm_member_variableConstants: all upper-case with words separated by underscores
SOME_CONSTANTFunctions:
lowerCamelCase
Tools¶
Autoformatter: clang-format.
Run:
./run-clang-format.py -r fresnelto see needed changes.Run:
clang-format -i file.ccto apply the changes to a specific file.Style configuration: See
.clang-format.
Note
We plan to provide change the style once clang-format 10 is available.
Documentation¶
Documentation comments should be in Javadoc format and precede the item they
document for compatibility with Doxygen and most source code editors. Multi-line
documentation comment blocks start with /** and single line ones start with
///.
Other file types¶
Use your best judgment and follow existing patterns when styling CMake, restructured text, markdown, and other files. The following general guidelines apply:
100 character line width.
4 spaces per indent level.
4 space indent.