Skip to content
This repository has been archived by the owner on May 19, 2019. It is now read-only.

Code style

korovkinand edited this page Feb 8, 2018 · 8 revisions

Read pep8 and use it as first place style guide

These rules may add, overwrite or emphasize pep8 ones:

  • Don't put large code with multiple actions in one line. Split it into several lines in accordance with functional logic
  • Give sensible names for functions, vars and constants. Function's name should be started with verb and shortly describe what func do. Constants should be written using UPPER case and placed at the top of file
  • Don't use temp 1-letter vars such as i. Every variable, even counter in loop should describe its meaning

Documentation

Read docstring docs

Highlights:

  • The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated. It should be documented whether keyword arguments are part of the interface.
  • Docstring should be used ONLY for explaining function's interface, not for its internal variables. For the explanation of code use plain comment above (or on right) of a line, you want to clarify.
  • The closing quotes are on the same line as the opening quotes. This looks better for one-liners.
  • There's no blank line either before or after the docstring.
  • The docstring is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...".
  • The one-line docstring should NOT be a "signature" reiterating the function/method parameters (which can be obtained by introspection). Don't do:

def function(a, b): """function(a, b) -> list"""

Clone this wiki locally