Code Smell 62 - Flag Variables

Subscribe to my newsletter and never miss my upcoming articles

Listen to this article

Flags indicate what happened. Unless their name is too generic.


  • Readability

  • Maintainability

  • Coupling


  1. Use meaningful names

  2. Try to avoid flags. They generate coupling.

Sample Code



We can search all the code for bad named flags.


  • Readability


Flags are widespread on production code. We should restrict their usage and use clear and intention revealing names.


More Info

If you lie to the compiler, it will get its revenge.

Henry Spencer

This article is part of the CodeSmell Series.

Comments (3)

Mr Rampage's photo

Flags cause me to flip out. I had the unfortunate experience of refactoring another developer's work that had a function with 7 input flags. The whole thing could've been achieved with a single Enum.

Maxi Contieri's photo

I agree

I'd check if I can double dispatch the enum, and then create polymorphic objects