Code Smell 24 - Boolean Coercions
11 November, 2022
2
2
0
Contributors
TL;DR: Don't do magic castings to boolean. You will regret it on a Friday night.
Problems
•
Hiding Errors
•
Accidental complexity coupled to one particular language.
•
Readability
•
Difficulty to hop among languages.
•
Solutions
1.
Be explicit.
2.
Work with booleans for boolean conditions. Not integers, not nulls, not strings, not lists. Just booleans.
Sample Code
Wrong
Right
Detection
Tags
•
Coercions
•
Primitive
Conclusion
Relations
More Info
It is not the language that makes programs appear simple. It is the programmer that make the language appear simple!