result = ???
TL;DR: Use good names always. Result is always a very bad name.
Problems
- Readability
Solutions
Rename result.
If you don't know how to name it, just name the variable with the same name as the last function call.
Don't use IDEs without automatic refactors.
Sample Code
Wrong
var result;
result = lastBlockchainBlock();
//
// Many function calls
addBlockAfter(result);
Right
var lastBlockchainBlock;
lastBlockchainBlock = findlastBlockchainBlock();
//...
// Many function calls
// we should refactor them to minimize space
// between variable definition and usage
addBlockAfter(lastBlockchainBlock);
Detection
We must forbid the word result to be a variable name.
Tags
- Readability
Conclusion
Result is an example of generic and meaningless names.
Refactoring is cheap and safe.
Always leave the campground cleaner than you found it.
When you find a mess on the ground, clean it, doesn’t matter who did it. Your job is to always leave the ground cleaner for the next campers.
Relations
More info
Credits
Code is like humor. When you have to explain it, it’s bad.
Cory House
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
Top comments (6)
Hi Tim.
Thank you very much for your possitive feedback.
You are absolutly right.
I try to write code smells in many different languages to be language agnostic.
In this case, I chose JS (which I don't master as you see)
I made some mistakes.
Now, with your advice, I've corrected them.
Thank you very much!
Cool, keep up the good work! I'll delete my comment.
There's no need. Thank YOU Tim!
hi,
code is about intent and with result we are sharing at the earliest the function exit value.
anyway your example is exaggerated as one could define result / res closer to function exit and also your function looks like doing too much :).
of course it is exagerated to show result problems.
even dough you define it and use it on next line you should definitively choose a better name.
Refactors are free