Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 62 — Flag Variables

Maximiliano Contieri
Dev Genius
Published in
1 min readFeb 8, 2021

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

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

Henry Spencer

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

Responses (1)

Write a response

I don't understand this code
```
$atLeastOneElementWasFound = true;
while (!$atLeastOneElementWasFound) {
````
How does this enter the loop? it's always false in the beginning....

--