Coding Style¶
Because slangpy is both a C++ library and a Python module, the coding style
should be consistent across both languages. Therefore we derive our coding
conventions from Python’s PEP 8
style guide.
Formatting¶
We use clang-format to format C++ code, and black to format Python code.
To format all C++ files in the project, you can run:
# Windows
tools/format_code.bat
# Linux and macOS
./tools/format_code.sh
To exclude files from formatting, add them to the .clang-format-ignore file.
Naming conventions¶
Class and struct names are written in
PascalCase.Function and member function names are written in
snake_case.Constant names are written in
UPPER_SNAKE_CASE.Variable names are written in
snake_case.Enum type names are written in
PascalCase, and enum values are written insnake_case.Private member variables are prefixed with
m_.
Properties¶
In C++, we use getter and setter functions to access class properties.
Getter functions are written as
const T& property() const;.Setter functions are written as
void set_property(const T& property);.
In Python, we expose these getters/setters as properties.
So while you do the following in C++:
auto value = object.property();
object.set_property(value);
You write the same in Python as:
value = object.property
object.property = value