Coding Standards
We want clean and nice (and good documented) python code. As easy and secure as possible. This means we should code like described in:
Heavy use of tools like pyChecker, pylint, pyindent and psyco:
- pyChecker and psyco are just need to be enabled (disabled by default) in startup-scripts
- pyindent comes with the python source (located in scripts directory)
Style Guide
- No tabs. Not anywhere. Always indent with 4 spaces.
- Line length: 80 chars.
- Use logger and logger-levels excessive: no debugging with print.
- Write testcases for everything.
- Mark privates with double underscore.
- Think OO not functional: use classes and inheritance instead of calling functions.
- Comment as much as possible. Make heavily use if docstrings to explain things.
- Comments should look like this:
# This is a comment about the code.
- Add docstrings to all methods (except init method), all classes and all modules.
- All log messages should be lower case only and without fullstops - no sentences.
- No string concatenation with slowly + better use %s for this.
Python Modules
- Module names: Python modules should have short, all-lowercase names, without underscores.
- Separate top-level function and class definitions with two blank lines.
- First line contains encoding, followed by license, followed by module description, followed by svn revision stuff, followed by imports.
Imports
- Imports should usually be on separate lines.
- Three Blocks: First standard modules. Second non-standard modules (dependencies) like cherrypy or sqlobject. Third block contains petunial modules.
- Use import instead of from module import ...
- Never use from module import *
Classes
- Method definitions inside a class are separated by a single blank line.
- Class names use the CamelCase convention. Classes for internal use have a leading underscore in addition.
- Method Names and Instance Variables: lowercase with words separated by underscores as necessary to improve readability.
- Inside a Class: first private methods then public methods.
- Inside init: first safe back method params, then all privates, later all publics if possible...
- Usually: one class per file - but never more then three classes per file.
you are here: WikiStart > CodingStandards

