A code that either returns or no returns at all
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 Smell 101 - Comparison Against Booleans
Maxi Contieri ⭐⭐⭐ ・ Nov 11 '21 ・ 2 min read
How to Get Rid of Annoying IFs Forever
Maxi Contieri ⭐⭐⭐ ・ Nov 9 '20 ・ 5 min read
Code Smells are just my opinion.
Photo by Jungwoo Hong on Unsplash
The central enemy of reliability is complexity.
Software Engineering Great Quotes
Maxi Contieri ⭐⭐⭐ ・ Dec 28 '20 ・ 13 min read
This article is part of the CodeSmell Series.
Top comments (1)
Cool series, thanks for sharing