The Daily Build

Icon

Software Development, version 3.0

3 Easy Ways to Stick to a Coding Standard

When you’re writing python, you don’t need a lot of debate over the minutiae 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.) I don’t have anything cookbook for this yet, but I’m working on it…
Share and Enjoy:
  • del.icio.us
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • FriendFeed
  • Posterous
  • email

Like this post? Get updates from my feed.

Related posts:

  1. Five Days to a Django Web App: Day Three, Coding Thanks for coming back for Day Three! [Note: Sorry...
  2. Who Else Wants Better Short Term Memory? In “Talent is Overrated”, Geoff Colvin at one point...
  3. Using Python’s ctypes to Call Into C Libraries The ctypes module makes loading and calling into a dynamic...
  4. Python Exception Handling: Cleanup and Reraise I’ve had this code around for a while and...
  5. Makefiles are Software Too This post was inspired by recent experience with some...

Category: python

Tagged: , , ,

One Response

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

Leave a Reply

Related Posts

Related posts:

  1. Five Days to a Django Web App: Day Three, Coding Thanks for coming back for Day Three! [Note: Sorry...
  2. Who Else Wants Better Short Term Memory? In “Talent is Overrated”, Geoff Colvin at one point...
  3. Using Python’s ctypes to Call Into C Libraries The ctypes module makes loading and calling into a dynamic...
  4. Python Exception Handling: Cleanup and Reraise I’ve had this code around for a while and...
  5. Makefiles are Software Too This post was inspired by recent experience with some...