Some coding rules currently applied when developping PycaWM
- First mandatory rule: respect PEP 8!
- No tabs! and 4 spaces for an indentation
- CamelCase for class names
- lower_case_with_underscores for functions and methods names
- Limit your lines to 80 characters
- Use single-quoted strings for normal strings and triple double-quoted strings for docstrings
Good:
'this is a string' """this is a docstring"""
Bad:
"this is a string" '''this is a docstring'''
- Use only new style classes (i.e. those who inherit from object)
- PycaWM needs at least python2.5, so you can use all the new features (ternary operator, 'with' statement, ...)
- No global variables (except if you REALLY need them)
- Convert your instance method to a classmethod if you don't need the instance
- Convert your classmethod to a staticmethod if you don't need the class
- Try to not have trailing whitespaces in your code
- No space before the ':' in an anonymous function
Good:
lambda wm, x, y: wm.move_pointer(x, y)
Bad:
lambda wm, x, y : wm.move_pointer(x, y)
- No '\' in a condition test (use parentheses instead)
Good:
if (self.x < 42 and self.y > 84 and
self.states.iconified):
pass
Bad:
if self.x < 42 and self.y > 84 and \
self.states.iconified:
pass
- When splitting an expression, always put the operator at the end of the line
Good:
if (self.x < 42 and self.y > 84 and
self.states.iconified):
pass
Bad:
if (self.x < 42 and self.y > 84
and self.states.iconified):
pass
- Use list() for an empty list (instead of [])
- Use dict() for an empty dictionary (instead of {})
- Docstrings and comments are good (especially docstrings) (maybe we should apply this rule a little bit more in PycaWM...)
- Generators are good (especially in for loops) (e.g. use xrange instead of range)
- Advanced features of python (descriptors, decorators, metaclasses, ...) are cool, you can use them (if they are useful for your problem)
- Try to limit your use of monkey-patching (PycaWM has a hook system to modify functions and methods at runtime, use only this system, please)
- Use a smart text editor (with a good python mode) (like emacs)
