Code Smell 118 - Return False

Code Smell 118 - Return False

Checking for a boolean condition to return a boolean value is awkward

Maxi Contieri
·Mar 5, 2022·

2 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 explicit booleans. Most boolean usages are code smells.


  • Declarativeness

  • Ninja Code

  • Implementative solutions


  1. Return a boolean proposition instead of checking a negation.

  2. Answer must be a business logic formula, not an algorithm.


When dealing with boolean formulas, it is more readable to show a business boolean formula than introduce a negated IF clause.

Programmers tend to return accidental implementative solutions instead of real business rules.

Sample Code


function canWeMoveOn() {
  if (work.hasPendingTasks())
    return false;
    return true;


function canWeMoveOn() {
  return !work.hasPendingTasks();


[X] Automatic

Based on syntax trees, we can safely refactor the code.


  • Boolean


Beware of returning booleans.

After the return, you will need an If statement which is also a code smell.


More Info


Photo by Morgan Housel on Unsplash

Thanks to Nico K. for this suggestion.

It's not at all important to get it right the first time. It's vitally important to get it right the last time.

Andrew Hunt

This article is part of the CodeSmell Series.

Share this