TL;DR: Check carefully your boolean expressions
- Refactor and remove obsolete code
When a function is designed to return an invariant value, it may be poor design, but it shouldn’t adversely affect the outcome of your program. However, when it happens on all paths through the logic, it is likely a mistake.
This rule raises an issue when a function contains several return statements that all return the same value.
# Gratuitous boolean expressions if a > 0 and True: print("a is positive") else: print("a is not positive")
if a > 0: print("a is positive") else: print("a is not positive")
Many linters can detect this problem by parsing execution trees.
Boolean expressions should be straightforward to read and understand.
Code Smells are just my opinion.
The central enemy of reliability is complexity.
This article is part of the CodeSmell Series.