3 Easy Ways to Stick to a Coding Standard

When you're writing python, you don't need a lot of debate over the minutiƦ of most coding standards. PEP 8 does that for you. Even better, there are some tools that make it really easy to stick to the standard.

Why do this? Well, for one thing it makes code reviews easier when everyone follows the same conventions. It also makes maintenance easier.

  1. pep8.py is a style checker that enforces the rules of PEP 8. The "official home" (?) at browsershots.org was dead as I was writing this. (Thanks GitHub!) Run pep8.py on your code and it will tell you where you've drifted from the standard.
  2. pylint is lint for python. It provides more functionality than pep8.py, but is not a strict superset. (pep8.py is pickier about whitespace issues.) Pylint is also configurable to enforce various naming rules. Like most lints, the SNR is pretty low, but you can turn off most of the noise and get a reasonable signal for the things you want to check.
  3. Subversion (as well as most other tools) can be configured to run a script every time you check in code. Run one or both of the above tools in the pre-commit hook and bad code will be rejected. (I'd be wary of doing this with pylint unless you've got the categories of "noisy" warnings turned off.)

Posted on 2009-08-25 by brian in python .

Comments

See http://reinout.vanrees.org/weblog/2009/09/14/pep8.html, I've just released pep8 on pypi. Thanks for the github link!

Reinout van Rees
2009-09-14 09:49:05
Comments on this post are closed. If you have something to share, please send me email.