Changes between Version 18 and Version 19 of DevNotes/DevGuide/CodingRules
- Timestamp:
- May 30, 2016 9:04:25 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevNotes/DevGuide/CodingRules
v18 v19 41 41 * There are two forms of docstrings: one-liners and multi-line docstrings. One-liners are for really obvious cases. They should really fit on one line. 42 42 * Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description. 43 * The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.) The docstring for a package (i.e., the docstring of the package's __init__.pymodule) should also list the modules and subpackages exported by the package.43 * The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.) The docstring for a package (i.e., the docstring of the package's {{{ __init__.py }}} module) should also list the modules and subpackages exported by the package. 44 44 * 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. 45 * The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its __init__method. Individual methods should be documented by their own docstring.45 * The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its {{{ __init__ }}} method. Individual methods should be documented by their own docstring. 46 46 47 47 … … 58 58 * Use box_car with underscores separating words for variable and method names. 59 59 * Use box_car with underscores for namespaces & directories 60 * Use _box_carwith a leading underscore for non-public methods and _CamelCase with a leading underscore for non-public classes.61 * Never use __box_car__with leading and trailing double underscores60 * Use {{{ _box_car }}} with a leading underscore for non-public methods and _CamelCase with a leading underscore for non-public classes. 61 * Never use {{{ __box_car__ }}} with leading and trailing double underscores 62 62 * Avoid one-letter variable names (unless is acceptable one letter variable name or it is justified by the math in the paper) 63 63 * Don't make long variable names just to keep lint happy: … … 111 111 }}} 112 112 * Avoid importing * from any module. This is a typically a waste of time and memory. This leads to bugs as well when for example you have "from math import *" and "from numpy import *" in the same file and then decide to reorder them. It also makes for harder to understand code since you don't know where the symbols are coming from. 113 * {{{ from module import *}}} is acceptable in {{{ __init__.py }}} if {{{ module.__all__ }}} defines the set of names being exported. 113 114 114 115 * Imports should be grouped in the following order: … … 124 125 * Exceptions should not be used for flow control, unless there is a very good reason for it 125 126 * Error codes from a method should never be returned - use exceptions 127 * Never use a blank except: statement since it interferes with KeyboardInterrupt. At a minimum, use except Exception:. 128 126 129 127 130 Coding Style … … 139 142 * Do not put spaces before commas, colons, or semicolons. 140 143 * Put one space around operators. 141 * However one can use no spaces with operators of higher priority, e.g., y = a*x**2 + b*x + c.144 * However one can use no spaces with operators of higher priority, e.g., {{{ y = a*x**2 + b*x + c}}}. 142 145 143 146 Miscellaneous … … 215 218 The proposed access to the core functionality should be consistent for all perspectives and straightforward to use. 216 219 217 * All known input arguments should be set in __init__, during instantiation, with proper checks220 * All known input arguments should be set in {{{__init__}}}, during instantiation, with proper checks 218 221 * Additional input data can be set directly through the @property decorator 219 222 … … 238 241 }}} 239 242 * All user accessible input/output data should be available through getters 240 __getattr__ and __setattr__should be avoided.243 {{{ __getattr__}}} and {{{__setattr__}}}} should be avoided. 241 244 * Main functionality should be exposed as a method with easy to understand name, e.g. calculate() and should return the results object/structure 242 245 * When defining the interface, type hints are an important part of the definition. Type hints are described in PEP-484 https://www.python.org/dev/peps/pep-0484 and should be added for all API methods.