Code Smell 115 - Return True

Code Smell 115 - Return True

Booleans are natural code smells. Returning and casting them is sometimes a mistake

Maxi Contieri
·Feb 20, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Table of contents

  • Problems
  • Solutions
  • Context
  • Sample Code
  • Detection
  • Tags
  • Conclusion
  • Relations
  • More Info
  • Credits

TL;DR: Don't return true or false. Be declarative.


  • Readability

  • Primitive Obsession

  • If/Else abuse


  1. Return truth value in a declarative way

  2. Replace IF With polymorphism.


Dealing with low-level abstractions, we usually return booleans.

When we create complex and mature software, we start to forget about this primitive obsession and care about real-world rules and identities

Sample Code


boolean isEven(int num){
     if(num%2 == 0){
       return true;
    } else {
       return false;}        


boolean isEven(int numberToCheck){
  //We decouple the what (to check for even or odd)
  //With how (the algorithm)
  return (numberToCheck % 2 == 0);     


[X] Automatic

Many linters can check syntactic trees and look for explicit true/value returns


  • Primitive


Search on code libraries for return true statements and try to replace them when possible.


More Info


Photo by engin akyurt on Unsplash

The good news is: Anything is possible on your computer. The bad news is: Nothing is easy.

Ted Nelson

This article is part of the CodeSmell Series.

Share this