-
Notifications
You must be signed in to change notification settings - Fork 230
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
- The
- 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:
- Indents with 4 spaces rather than tabs
- See whitespace guidelines for when to include spaces
- 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 offrom .resonance import generateResonanceStructures
) - Remove unnecessary imports
- Avoid wildcard imports (e.g.,
- 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