Open3D style guide#
Style checker#
Install dependencies#
conda activate <your-virtual-env>
# The version of the style checker is critical.
# cd to the root of the Open3D folder first.
pip install -r python/requirements_style.txt
Check or apply style#
Option 1: Run the style checker directly.
python util/check_style.py
python util/check_style.py --apply
Option 2: Configure the project and run make
.
mkdir build
cd build
cmake ..
# Ubuntu/macOS
make check-style
make apply-style
# Windows
cmake --build . --target check-style
cmake --build . --target apply-style
Coding style#
Consistent coding style is an important factor of code readability. Some principles:
Code itself is a document. Name functions and variables in a way they are self explanatory.
Be consistent with existing code and documents. Be consistent with C++ conventions.
Use common sense.
We generally follow the Google C++ Style Guide, with a few modifications:
Use 4 spaces for indent. Use two indents for a forced line break (usually due to the 80 character length limit).
Use
#pragma once
for header guard.All Open3D classes and functions are nested in namespace
open3d
.Avoid using naked pointers. Use
std::shared_ptr
andstd::unique_ptr
instead.C++11 features are recommended, but C++14 and C++17 are also accepted.
We also recommend reading the C++ Core Guidelines.
For Python, please use Google style guidelines, as shown here.