Skip to content

Contributing Style Guide

Oliver Roick edited this page Jan 19, 2016 · 8 revisions

Python

General rules

We write Python3.

We follow PEP8 conventions throughout all our Python code. Key principles include:

  • Always use spaces for indentation. Four spaces make one tab.
  • Maximum line length is 79 characters.
  • Always encode source files in UTF-8.

Imports

Try to keep your imports small and only import those definitions of a module that you actually need in your script.

from django.views.generic import CreateView, TemplateView

If you, however, need many definitions from a single module it's more readable to import the module and call the definitions from the module.

Don't do:

from django.views.generic import (CreateView, TemplateView, ListView,
    UpdateView, DeleteView)

Do this instead:

from django.views import generic as generic_views

(...)

generic_views.CreateView(...)

Never import * from a module. This can significantly affect performance and might have other unwanted consequences.

Don't do this, ever:

from django.views import *

A few words on strings

Use single quotes for symbol-like strings and double quotes for natural language messages:

MESSAGES = {
    'English': "This organisation has no members.",
    'German':  "Diese Organisation hat keine Mitglieder."
}

Use triple-double quotes for doc strings:

def get_members(self):
    """Returns all members"""
    return self.members

Make interpolated strings readable:

"{org_name} has {num_members} members.".format(
    org_name="Habitat for Humanity",
    num_members=10
)

Never use string concatenation—it makes internationalisation impossible.

Text editors

Use the IDE or text editor you personally prefer.

The repository contains an EditorConfig file, which helps developers maintain consistent coding styles between different editors and IDEs. EditorConfig plugins are available for most editors:

Lint your code using Flake8 for potential errors before committing. Flake8 provider are available for several text editors:

Javascript

Airbnb has pulled together comprehensive ES6 and React guides that we follow for everything JavaScript.

Use ESLint to lint your JS code:

Clone this wiki locally