STATUS: current as of 9/13/2005

Coding Standards

These are just some guidelines I've been trying to follow for this codebase since it started several years ago. - Michal

Languages

We use python almost exclusively. There are many reasons for this, but the main ones are the short learning curve, restricted execution support, and general clarity of python code.

General Style

the basics

(unless there's a real good reason not to - eg, modifying or extending someone else's code)

Note: docstrings look like this:
def good():
   """
   this is a nice docstring
   """

def bad():
   """this is ugly!"""

capitalization / punctuation

avoid:

avoid names_like_this (except for get_, set_, test_, etc) (2005: i've kind of drifted on this one.)

variable naming conventions

Generic variables. (Only if there's not a more obvious/specific variable name):

databases

Testing

We're big on unit testing. Every class should have at least one test case. Probably quite a few. When writing programs, code the unit test first.

We use an open source python testing tool called PyUnit. PyUnit is now part of the standard python distribution, so if you have ptyhon you already have it. PyUnit allows you to build test cases and compile them into test suites. We have some standards:

(2005: most of the older code doesn't reflect these standards yet

include this code at the bottom of each test file so it can be run directly without need for snake.py

:
if __name__=="__main__":
    unittest.main()

IMPORTANT: TESTS SHOULD NOT CONNECT TO A DATABASE! That's what arlo.MockClerk is there for.

It is also important to stick to this standard for the purposes of a nightly distribution-bundling mechanism (STILL not implemented) that will make the latest CVS code available in a developer's tarball.

doctests

Doctests also run through snake.py and live in the ./spec directory... These are XHTML files with embedded doctest transcripts.