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.

General rules
These rules apply to all code, no matter the language:


 * Indent using 4 spaces
 * This is also used by Analytics Engineering (Python, Scala, Java, JavaScript, SQL), Search Platform (Java), and Site Reliability Engineering (Puppet).

SQL
We follow Kickstarter's SQL style guide, except that we indent with 4 spaces instead of 2.

Key points:
 * 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 defer to PEP-8.

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: