Coding style - General practices

  • Don’t put an else right after a return (or a break). Delete the else, it’s unnecessary and increases indentation level.

  • Don’t leave debug printfs or dumps lying around.

  • Use JavaDoc-style comments.

  • When fixing a problem, check to see if the problem occurs elsewhere in the same file, and fix it everywhere if possible.

  • End the file with a newline. Make sure your patches don’t contain files with the text “no newline at end of file” in them.

  • Declare local variables as near to their use as possible.

  • For new files, be sure to use the right license boilerplate, per our license policy.

Mode line

Files should have Emacs and vim mode line comments as the first two lines of the file, which should set indent-tabs-mode to nil. For new files, use the following, specifying two-space indentation:

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

Be sure to use the correct Mode in the first line, don’t use C++ in JavaScript files.