From 6ea78bcbcd9abdd37a0d71dd1eeff8e1f5f1a79f Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Tue, 1 Dec 2020 10:57:24 +0100 Subject: [PATCH] Remove misc python programming recommendations We want to keep the style guide as minimal as possible. A separate miscellaneous programming recommendations document might be added in the future. --- python.md | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/python.md b/python.md index 05c6a3e..68b8e1a 100644 --- a/python.md +++ b/python.md @@ -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 - - - -- 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`.