Product Analytics/Style guide

In order to speed code exchange and review, the Product Analytics team follows these style guides. We encourage others involved in the Wikimedia analytics ecosystem to follow them as well, or suggest other style guide we should converge with.

SQL
We follow Kickstarter's SQL style guide.

Key points:
 * Indent using 2 spaces, not tabs.
 * Write SQL keywords in all caps (e.g., ,  )
 * Variable names are lowercase, with spaces represented by underscores (e.g., not ).
 * goes at the beginning of a line, not at the end.

Python
We follow MediaWiki's Python coding conventions, which for the most part defers to PEP-8.

However, we deviate by indenting with 2 spaces instead of 4.

R
We follow the tidyverse style guide.

Key points:


 * Use lowercase letters and snake case (underscores for separation of words) for naming functions and variables.
 * should always have a space before it, and should usually be followed by a new line. After the first step, each line should be indented by two spaces.
 * If a function call is too long to fit on a single line, use one line each for the function name, each argument, and the closing.

Further recommendations:


 * Be liberal with code comments
 * If attaching a package namespace – e.g.  instead of   – add notes (reminders) why a particular package is being used and/or which specific function you're using.
 * If it's not immediately clear what something is, don't be afraid to clarify it in code.

For example: