Skip to content

Programming Style Guide

Max Liu edited this page Oct 30, 2017 · 3 revisions

In general, refer to the Python Style Guide for reference.

Particular items to keep in mind:

  • Code organization:
    • The rmgpy package contains all of the functionality of RMG
    • Unit tests associated with a particular module should be located in moduleTest.py
    • Place all custom exceptions in rmgpy/exceptions.py
  • Naming conventions:
    • RMG now officially follows PEP 8 naming conventions
    • New code should comply with these guidelines, and old code can be converted as convenient
    • module names are in lowercase, and preferably one word long
    • Class and Exception names start with capital letters (e.g., CamelCase)
    • functions and methods are lower case with underscores (e.g., lowercase_with_underscores)
    • instances and variables are lower case with underscores (e.g., lowercase_with_underscores)
    • constants are upper case with underscores (e.g., CAPS_WITH_UNDERSCORES)
  • Spacing:
  • Imports:
    • Avoid wildcard imports (e.g., from rmg.molecule import *)
    • Absolute imports are preferred over relative imports (e.g., from rmgpy.molecule.resonance import generateResonanceStructures instead of from .resonance import generateResonanceStructures)
    • Remove unnecessary imports
  • Exceptions:
    • Provide a helpful message when raising an exception
    • When catching an exception, use the most specific exception class that is reasonable
  • Logging:
    • Use the logging module to print messages; never use print statements
    • Use appropriate logging levels for messages