Skip to main content

Command Palette

Search for a command to run...

Code Smell 79 - TheResult

If a name is already used, we can always prefix it with 'the'.

Published
1 min read
Code Smell 79 - TheResult

TL;DR: don't prefix your variables.

Problems

  • Readability

  • Meaningless names

Solutions

  1. Use intention revealing names.

  2. Avoid Indistinct noise words.

Refactorings

Sample Code

Wrong

var result;

result = getSomeResult();

var theResult;

theResult = getSomeResult();

Right

var averageSalary;

averageSalary = calculateAverageSalary();

//..

var averageSalaryWithRaises;

averageSalaryWithRaises = calculateAverageSalary();

Detection

As with many of our naming conventions, we can instruct our linters to forbid names like theXxx....

Tags

  • Readability

Conclusion

Always use intention revealing names.

If your names collide use local names, extract your methods and avoid 'the' prefixes.

Relations

More info

Credits

Photo by Josue Michel on Unsplash


One difference between a smart programmer and a professional programmer is that the professional understands that clarity is king. Professionals use their powers for good and write code that others can understand.

Robert C. Martin


This article is part of the CodeSmell Series.

Code Smells

Part 1 of 50

In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.