The CHIRP Radio Style Guide

Coding Conventions

In general, Python code should follow the guidelines and conventions outlined in PEP 8.

A few additional rules:

  • One-character variable names are strongly discouraged, except for variables of iteration.
  • Avoid “power features” like metaclasses, import hacks, reflection, etc. These features are occasionally necessary for low-level hacks in core infrastructure, but should generally not occur in applications. Simplicity in code is a virtue.
  • Code should always be accompanied by unit tests.
  • Always use new-style classes by deriving from object in base classes.

Imports

Long lists of imports can be confusing and difficult to scan and maintain. To avoid this, the encouraged order to imports is.

  • First standard Python modules.
  • Then core Django modules.
  • Then Google App Engine-specific modules.
  • The core chirpradio infrastructure.
  • Finally, your application or subcomponent.

Each group of imports should occur in alphabetical order.

TODO Comments

In the code, you will occasionally see comments of the form # TODO(username): Need to do so-and-so in the future.

The “username” indicates the person who originally made the note, not the person who is assigned to fix it. The name is there so that you can know who to ask if you have questions about the note.

If you are new to the project, a good way to get started is to search for TODO items and try to do them.