Development/CodingStyle

Transifex Coding Style

Here are some notes on the common style we use for stuff landing in Transifex.

  • Code follows the guidelines described in the standard Python Coding Style of PEP-8. Docstrings follow PEP-257.
  • Additions to PEP8:
  • Long strings should be wrapped as shorter strings joined together with Python's implied line continuation inside parentheses, with the space character on the first line. Here is an example:

    print ("Please choose only one of the two overwrite options: "
           "Either substitute an existing file or provide a name for "
           "a new one.")
    

    and not:

    print "Please choose only one of the two overwrite options:" + \
          " Either substitute an existing file or provide a name for" + \
          " a new one."
    
  • Commit messages should have a short first line and optionally more information after a blank newline:

    Short (50 chars or less) summary of changes (#ticket)
    
    More detailed explanatory text can follow after a blank line, if
    necessary. Wrap to about 72 characters or so.
    
    If there is a ticket associated, include it in the summary line. Prefix
    line with "bugfix:" and "trivial:" for bugfixes and trivial commits
    respectively.
    
     - Bullet points are okay, too. Typically a hyphen or asterisk is used
       for the bullet, preceded by a single space, with blank lines between
       items.
    
     - Use a hanging indent, like above.
    

    Hint: Use :set tw=72 (could sneak into ~/.vimrc) or export EDITOR="vim -c 'set tw=72' just before the commit.

  • Model filtering should be in the form:

    Module.query.filter_by(name='foo')
    

    and not:

    Module.query.filter(Module.name=='foo')
    
  • RestructuredText is used for documentation.