# Code Smell 62 - Flag Variables

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

# Problems

-  Readability
 
- Maintainability

- Coupling

# Solutions

1.  Use meaningful names

2. Try to avoid flags. They generate coupling.

# Sample Code

## Wrong

%[https://gist.github.com/mcsee/694068de9cd2bbb8592d1a14bd89fe9e]

## Right

%[https://gist.github.com/mcsee/8a0de13a6fb13ae4da9c51a1b91c9705]

# Detection

We can search all the code for bad named flags.

# Tags

- Readability

# Conclusion

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

%[https://maximilianocontieri.com/code-smell-51-double-negatives]

%[https://maximilianocontieri.com/code-smell-07-boolean-variables]

# More Info

%[https://en.wikipedia.org/wiki/Boolean_flag]

%[https://martinfowler.com/bliki/FlagArgument.html]

%[https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab]

* * *

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

_Henry Spencer_

* * *
 
%[https://mcsee.hashnode.dev/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://mcsee.hashnode.dev/how-to-find-the-stinky-parts-of-your-code]
