Changes between Version 11 and Version 12 of DevNotes/DevGuide/CodingRules
- Timestamp:
- May 30, 2016 7:42:09 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DevNotes/DevGuide/CodingRules
v11 v12 94 94 95 95 * Imports should be grouped in the following order: 96 standard library imports97 related third party imports98 local application/library specific imports96 1. standard library imports 97 2. related third party imports 98 3. local application/library specific imports 99 99 * Put a blank line between each group of imports. 100 100 101 101 Exception Handling 102 102 103 Use if and try/except block to test for errors that could happen in normal program operation 104 105 If you catch an exception and all you do is calling pass or print, you have not dealt with the error properly 106 Exceptions should not be used for flow control, unless there is a very good reason for it 107 Error codes from a method should never be returned - use exceptions 103 * Use if and try/except block to test for errors that could happen in normal program operation 104 * If you catch an exception and all you do is calling pass or print, you have not dealt with the error properly 105 * Exceptions should not be used for flow control, unless there is a very good reason for it 106 * Error codes from a method should never be returned - use exceptions 108 107 109 108 Coding Style 110 109 111 110 When in doubt - follow PEP 8 (https://www.python.org/dev/peps/pep-0008/) 111 112 112 Indentation 113 113 114 Use 4 spaces to indent, not tabs.115 Indent 4 spaces per nested level.114 * Use 4 spaces to indent, not tabs. 115 * Indent 4 spaces per nested level. 116 116 117 117 Spaces in Expressions & Statements 118 118 119 Do not put spaces around parentheses, brackets, or curly braces.120 Do not put spaces before commas, colons, or semicolons.121 Put one space around operators.122 However one can use no spaces with operators of higher priority, e.g., y = a*x**2 + b*x + c.119 * Do not put spaces around parentheses, brackets, or curly braces. 120 * Do not put spaces before commas, colons, or semicolons. 121 * Put one space around operators. 122 * However one can use no spaces with operators of higher priority, e.g., y = a*x**2 + b*x + c. 123 123 124 124 Miscellaneous 125 125 126 Limit lines to a maximum of 79 characters.127 Do not put semicolons at the end of lines.128 Avoid using magic numbers126 * Limit lines to a maximum of 79 characters. 127 * Do not put semicolons at the end of lines. 128 * Avoid using magic numbers 129 129 Use: 130 max_bins = 7 131 if i < max_bins: 130 {{{ 131 #!div style="font-size: 80%" 132 {{{#!python 133 max_bins = 7 134 if i < max_bins: 135 }}} 136 }}} 132 137 Not: 133 if i < 7 134 138 {{{ 139 #!div style="font-size: 80%" 140 {{{#!python 141 if i < 7 142 }}} 143 }}} 135 144 Comments in the code 136 145