Skip to content
mattsmart edited this page Jul 13, 2015 · 3 revisions

General coding/style guide for the main languages we're working with. These currently/will include:

  • Python
  • MATLAB

Python

We're using Python version 2.7.x (https://www.python.org/downloads/), but you can probably get away with 2.5 or 2.6. To keep our code consistent, we're following the standard PEP-8 style guide (https://www.python.org/dev/peps/pep-0008/). If you're looking for an editor, PyCharm (https://www.jetbrains.com/pycharm/download/) is pretty good and follows PEP-8.

Some quick tips:

  • indents are 4 spaces
  • lines shouldn't exceed 121 characters
  • one newline at EOF (end of file)
  • two newlines between top-level functions and classes, one newline between in-class functions
  • use all lowercase and underscores for variable names and function names
  • use asserts to make sure your code behaves properly
  • include a test directory for new modules, or update the test directory if you're adding to a module
  • document your code!

Function documentation should include a one-line message and input/output descriptions for all major functions. Example:

def sum_and_square(x, y):
    """Adds and then squares two scalars x and y
    Args:
        x: scalar (int or float)
        y: scalar (int or float)
    Returns: 
        scalar (int or float)
    """
    return (x + y) ** 2

add some notes on test directories / maybe unit tests for modules

MATLAB

To be written

Clone this wiki locally