-
-
Notifications
You must be signed in to change notification settings - Fork 17
Code Style
Quintin edited this page Jun 15, 2022
·
14 revisions
- Use clang-format before committing. Read this for VSCode and for CLion it should work automatically by detecting the
.clang-format
file. -
Never use raw pointers, prefer smart pointers (usually
std::shared_ptr
). - Check if something exists in the standard library before you reinvent the wheel!
- Prefer
static_cast
etc. instead of C style cast - Use
auto
on iterator types (ranged for) and when the type is obvious, for example casting orstd::make_shared
- Pass primitives by value (
int
,float
, etc.) and complex types by reference or smart pointers - Do not use references (&) types for out parameters in functions, prefer returning a struct
- Prefer using an explicit struct instead of
std::pair
orstd::tuple
- Currently
pycodestyle
,flake8
, andisort
are used as a basic check. Read this for VSCode, ideally you adhere topylint
too but it can be very strict so right now it wont be enforced.- To install use pip (
pip install isort pycodestyle flake8 pylint
) - While in the
src
directory runisort .
,pycodestyle . --max-line-length=119
,pylint. --max-line-length=119
, etc.
- To install use pip (
- If you are writing a function, please use type hinting for the signature. For other places, only use if necessary, for example a situation where the types are confusing.
- Document your code! Use the reST standard specifically
Here is a good concrete example:
def pos_distance_to(self, p: SE3) -> float:
"""
Get the euclidean distance from the position of this SE3 pose to the position of another SE3 pose.
:param p: another SE3 pose object
:returns: euclidean distance between the two SE3 poses
"""
return np.linalg.norm(p.position_vector() - self.position_vector())