Code Smell 62 - Flag Variables

Maxi Contieri - Feb 8 '21 - - Dev Community

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

Right

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

More Info

Wikipedia


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

Henry Spencer


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player