Code Smell 24 - Boolean Coercions

Subscribe to my newsletter and never miss my upcoming articles

Booleans should be just True and false


  • Hiding Errors

  • Accidental complexity coupled to one particular language.

  • Readability

  • Difficulty to hop among languages.

  • IFs


  1. Be explicit.

  2. Work with booleans for boolean conditions. Not integers, not nulls, not strings, not lists. just booleans.

  3. Fail fast

Sample Code



This is a language feature. Some strict languages show warnings with this magic wizardry.


  • Coercions

  • Primitive


Some languages encourage doing some magic abbreviations and automatic castings. This is a source of errors and a Premature Optimization warning.

We should always be as explicit as possible.


More Info

It is not the language that makes programs appear simple. It is the programmer that make the language appear simple!

Robert Martin

This article is part of the CodeSmell Series.

No Comments Yet