-
Notifications
You must be signed in to change notification settings - Fork 135
RAVEN Software Coding Standard
Andrea Alfonsi - INL edited this page Sep 14, 2018
·
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:
- Use 2 spaces for each indent level.
- Class names should start with a Capital letter.
- Other variables should be camelBack case.
- 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, unicode_literals, absolute_import
import warnings
warnings.simplefilter('default',DeprecationWarning)
before any code.
- 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.