Skip to content

Coding conventions

Peter Corke edited this page Nov 1, 2020 · 4 revisions

Style

PEP 8 rules

We aspire to the Zen of Python

docstrings

see detailed doc string conventions here

Package imports

At the top of each file we import packages in the following order

  • Standard Python packages
  • NumPy
  • SciPy
  • Matplotlib
  • Spatial Math Toolbox
  • Robotics Toolbox
  • all others

Unit testing

We use pytest

Code quality

We use codecov to analyse and display unit test coverage, we aim for over 90% coverage.

We use LGTM to analyse and display code quality, we aim for an A rating.

Coding patterns

We strive to be Pythonic rather than MATLABish.

  • we prefer for x in X rather than for i in range() and indexing. If X is a NumPy array then x iterates over matrix rows. If we do need an index as well as the object, then use enumerate().
  • we test arguments for appropriateness and raise a ValueError or TypeError
  • for argument checking we use spatialmath.base.argcheck
    • we test for a scalar argument using isscalar
    • we test for a vector argument using isvector which accepts a Python list, tuple or NumPy array
Clone this wiki locally