Skip to content

Commit

Permalink
Remove misc python programming recommendations
Browse files Browse the repository at this point in the history
We want to keep the style guide as minimal as possible.  A separate
miscellaneous programming recommendations document might be added
in the future.
  • Loading branch information
lukpueh committed Dec 1, 2020
1 parent e8f1e72 commit a0b32a9
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions python.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,44 +167,3 @@ Use `f"...{var}"` when writing Python 3.6+ code, or `"...{0}".format(var)`
anywhere. `"..." + var` may be used for simple cases, but beware of pitfalls
such as easily missed whitespace, or `var` not being a string. Don't use the
old `"...%s" % var`-notation.


## Programming Recommendations

### Miscellaneous

<!-- TODO: This recommendation is an updated remainder of the old style guide.
It seems a bit lost here. -->

- Avoid large vertical separation of `if` and `else` keywords.
```python
# NO:
if bizbaz:
frobnicate(flimflam)
...
...
...

else:
raise YamException("No bizbaz, no frobnicate!")
```
Use the *"return early"* pattern, if the `else` clause would raise an
exception or returns:

```python
# YES:
if not bizbaz:
raise YamException("No bizbaz, no frobnicate!")

frobnicate(flimflam)
...
...
...

```
Returning early is generally useful to avoid excessive levels of nesting
(aka. *"arrowhead anti-pattern"*).

If returning early is not an option, and `if` and `else` are thus both
needed, it is slightly preferable to keep the shorter clause first, so that
the `else` isn't too far from the `if`.

0 comments on commit a0b32a9

Please sign in to comment.