Skip to content

Instantly share code, notes, and snippets.

@jonathanpenn
Forked from joefiorini/rep8.textile
Created June 16, 2009 14:49
Show Gist options
  • Save jonathanpenn/130712 to your computer and use it in GitHub Desktop.
Save jonathanpenn/130712 to your computer and use it in GitHub Desktop.

Introduction

Forward (from PEP 8)

One of Guido’s key insights is that code is read much more often than it
is written. The guidelines provided here are intended to improve the
readability of code and make it consistent across the wide spectrum of
Python code. As PEP 20 6 says, “Readability counts”.

A style guide is about consistency. Consistency with this style guide is
important. Consistency within a project is more important. Consistency
within one module or function is most important.

But most importantly: know when to be inconsistent — sometimes the style
guide just doesn’t apply. When in doubt, use your best judgment. Look
at other examples and decide what looks best. And don’t hesitate to ask!

Two good reasons to break a particular rule:

(1) When applying the rule would make the code less readable, even for
someone who is used to reading code that follows the rules.

(2) To be consistent with surrounding code that also breaks it (maybe for
historic reasons) — although this is also an opportunity to clean up
someone else’s mess (in true XP style).

Code Layout

Indentation

2 spaces per tab level. Actually, I (Jonathan) would prefer 4 since it makes it really uncomfortable to nest code.

Imports (requires?)

Whitespace in Expressions and Statements

Comments

Doc strings (umm, rdoc comments?)

Version Bookkeeping (um, n/a?)

Naming Conventions

Programming Recommendations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment