6. Mamba coding style guide¶
Like other Python projects, Mamba try to follow the PEP-8 and Sphinx as docstrings conventions. Make sure to read those documents if you intent to contrbute to Mamba.
6.1. Naming conventions¶
- Package and module names must be all lower-case, words may be separated with underscores. No exceptions.
- Class names are CamelCase e.g. ControllerManager
- The function, variables and class member names must be all lower-case, with words separated by underscores. No exceptions.
- Internal (private) methods and members are prefixed with a single underscore e.g. _templates_search_path
6.2. Style rules¶
- Lines shouldn’t exceed 79 characters length.
- Tabs must be replaced by four blank spaces, never merge tabs and blank spaces.
- Never use multiple statements in the same line, e.g.
if check is True: a = 0
with the only one exception for conditional expressions - Comprehensions are preferred to the built-in functions
filter()
andmap()
when appropiate. - Only use a
global
declaration in a function if that function actually modifies a global variable. - Use the
format()
function to format strings instead of the semi-deprecated old ‘%s’ % (data,) way. - Never use a print statement, we always use a
print()
function instead. - You never use
print
for logging purposes, for that you usetwisted.python.log
methods.
6.3. Inconsistences¶
Mamba uses Twisted as its main component and Twisted doesn’t follow PEP-8 coding style and is never going to follow it. Because of that, be aware of some inconsistences where we use twisted objects and methods.
We want to be clear on that: we never use Twisted coding name conventions in exclusive Mamba code, no exceptions to this rule.