Coding Style#
It is useful to articulate a set of coding conventions for your project to maintain consistency and to help your developers quickly understand code. Although trivial from the computer’s perspective, this has several advantages for the users and developers:
Coding Efficiency: Developers need not waste time deciding what style to use.
Documentation: Following certain conventions can allow documentation tools to extract and display information clearly.
Python#
import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Python has its own style guide described in PEP-8, most of which is enforced by
Black – “The uncompromising code formatter”. I recommend having your editor run
black whenever you save your code. This removes most discussion about where spaces
should appear, formatting loops, lists etc.
Docstrings#
We use Napoleon to extract our docstrings, so please follow the NumPy Style guide, falling back to the syntax used by Napoleon when ambiguous. This aids in generating our API Reference.