Skip to content

Code readability matters

Kim Whitehall edited this page Sep 7, 2015 · 11 revisions

This code base is currently being refactored to follow the PEP8 - Style Guide for Python.

Linting GTG code

A configure file called gtg_lint_file is provided for use with PyLint. Currently we are using Python 2.7.x and pylint == 1.4.1 in this repo. Use the following command to lint using the config file provide. pylint --rcfile=../gtg_lint_file <your_file>

A summary of important styling components for the GTG codebase

  1. Spaces are used for indentation. NO TABS!!

  2. Limit lines of code to a maximum of 120 characters.

  3. Imports should ALL be placed at the top of the file in the following order

    • Standard library imports

    • Third party imports

    • Local application/ library specific imports

  4. Use single-quoted strings

  5. Class names should use the CapWords convention.

  6. Function names should use lower_case_with_underscores

  7. Variable names should use mixedCase

  8. Constants are defined on a module level and written in all capital letters with underscores separating words. e.g. ECCENTRICITY_THRESHOLD_MAX = 1.0

  9. Please write comprehensive extensive document strings for all modules, functions and classes following these standards:

    • Place docstring below the def line.

    • Follow the format below for the docstring Purpose:: A sentence or two describing the purpose of the module, function or class

Input:: name of parameter: a input type representing definition e.g. prunedGraph: a Networkx Graph representing the cloud clusters

Returns:: name of variable: a input type representing definition e.g. finalMCCList: a list of list of tuples representing a MCC

Generates:: output type in location for description e.g. plots in /images for each MCS cloud elements

Assumptions:: As it relates to the code and the repo, if necessary.

  1. Be consistent with the codebase regarding whitespaces in expressions.

e.g. if a == 4: print a

    `cloudElement['time']`

    `x = x*2 + 1`

    `c = (a+b) / (a-b)`

    `findCloudElements(mergImgs,timelist,TRMMdirName=None)`

For the generalizations of these rules, see Tim Peters' guidelines in PEP20.