Skip to content

RAVEN Software Coding Standard

Andrea Alfonsi - INL edited this page Dec 4, 2019 · 6 revisions

RAVEN follows the Chromium coding standard for Python code (see https://www.chromium.org/chromium-os/python-style-guidelines). Among the several rules, RAVEN strictly enforces the following:

General coding standards

  • Use 2 spaces for each indent level.
  • Class names should start with a Capital letter.
  • Other variables should be camelBack case. (The test system uses PEP 8 for variable naming.)
  • Private variables start with two underscores: __
  • Protected variables should start with one underscore: _
  • Function definitions should have at least one line of white-space afterwards.
  • except: with no exception must never be used
  • In order to be compatible with Python 3.x releases, any Python 2.x code, must have:
from __future__ import division, print_function, absolute_import

before any code. (Importing unicode_literals is allowed as part of the import, but only should be used if it is useful.)

  • The so-called "wild importing" approach is FORBIDDEN, i.e. :
from aModule import *
  • Multiple statements on one line are not allowed. For example the following is forbidden:
if makeAnimal: self.raiseAMessage("we just increased the MOOSE herd population")

and should be changed to:

if makeAnimal: 
  self.raiseAMessage("we just increased the MOOSE herd population")
  • Tuple unpacking and packing should only be used when needed. For example:
a, b = 0, 1

should be rewritten to be:

a = 0
b = 1

However, using it for function returns and swapping is allowed, since it saves temporary variables:

a, b = b, a

or:

a, b = funct()

are allowed.

  • Lines longer than 120 characters must be split.