cover-img

Code Smell 79 - TheResult

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

29 June, 2023

0

0

0

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

TL;DR: don't prefix your variables.

Problems

  • Readability
  • Meaningless names

Solutions

  1. Use intention revealing names.
  2. Avoid Indistinct noise words.

Refactorings

Refactoring 006 - Rename Result Variables

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

Code Smell 38 - Abstract Names

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

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code

0

0

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.