PEG coding_standard--vegai: Coding Standard

Author: Vesa Kaihlavirta
Revision: 1.15
Status: Incomplete

Our coding standard (/gzz/CODING) requires revising, mainly because of the large and growing amount of python code.



These apply to all *.py (and possibly *.test).

  1. Header comments should include full module name of the file (eg. gzz/modules/pp/ would have gzz.modules.pp.demotest).

  2. Header comments should include authors.

  3. After header comments, rcsId: rcsId = "$Id: peg.rst,v 1.15 2003/02/05 13:44:06 Vegai Exp $"

  4. After rcsid, the imports (unless there's a good reason to delay importing).

    • Prefer "import foo" to "from foo import bar".

    • Prefer "from foo import bar" to "from foo import *".

    • No more than one import package in one line, except when importing gzz and java:

      import os, sys   # Preferably no.
      import os        # Yes.
      import sys
      import gzz, java # Yes.
  5. Imports should be grouped in the following order:

    • standard python imports
    • 3rd party python imports
    • java imports
    • gzz imports
    • imports should be in alphabetical order in the groups
  6. Code should be structured so that it can be imported and re-used, for example by putting state in classes instead of the module namespace. Executable code in module namespace is discouraged -- except for "if __name__=='__main__':"

  7. Class names are CapitalizedWords.

  8. Class methods and attributes are mixedCase.

  9. Functions and variables are mixedCase.

  10. Tab-size is 8, indentation at 4 spaces.

  11. Run make committable before committing code.

    • converts tabs to 8 spaces
    • runs tests