This guide will help you understand our code style, paradigms, and best practices to ensure consistency and maintainability.
- Follow PEP 8 for Python code style.
- Use 4 spaces for indentation.
- Keep lines under 80 characters.
- Use meaningful variable and function names.
- Add docstrings to all public modules, classes, and functions.
- All code written must be compatible with python >= 3.8.
- Group imports into two sections: library imports and local imports.
- Use absolute imports for clarity.
e.g.
import os
import sys
import numpy as np
import rclpy
from mhsboat_ctrl.tasks import Task- Use type hints for function signatures and variable declarations.
- Use
Optionalfor variables that can beNone. - Write docstrings for functions that describe everything the function does and requires.
- Use comments to explain the purpose of complex code blocks.
- Comments should not describe basic code. Variable names should be obvious, and functions should encapsulate functionality.
- Use
# TODO:to indicate areas that need improvement or additional features. Please also create an issue describing the needed changes.
- Don't. If you find yourself copying and pasting code, it's a sign that you should refactor the code into a function or class.
- Use classes to encapsulate related data and functions.
- Inherit from base classes to promote code reuse and maintainability.
- Use properties to provide controlled access to class attributes.
- Organize code into modules and packages to promote separation of concerns.
- Each module should have a single responsibility.
- Use the
Taskclass for defining tasks and ensure each task is in its own file.
- Write unit tests for all new features and bug fixes.
- Use the
pytestframework for testing. - Ensure tests cover edge cases and potential failure points.
- Update the README.md and other relevant documentation with any new features or changes.
- Use docstrings to document functions, classes, and modules.
- Use the
ament_flake8linting tool to verify styles. - All style guidelines align with pep8. Any explicit modifications are contained in the
setup.cfgfile. - To automatically apply styles, you can run
autopep8 --in-place --aggressive -r <dir-to-check>.
- Use meaningful commit messages that describe the changes made.
- Create a new branch for each feature or bug fix.
- Submit pull requests for review before merging into the main branch.