DEV Community

Cover image for Code Smell 81 - Result
Maxi Contieri
Maxi Contieri

Posted on • Originally published at maximilianocontieri.com

Code Smell 81 - Result

result = ???

TL;DR: Use good names always. Result is always a very bad name.

Problems

  • Readability

Solutions

  1. Rename result.

  2. If you don't know how to name it, just name the variable with the same name as the last function call.

  3. Don't use IDEs without automatic refactors.

Sample Code

Wrong

var result;

result = lastBlockchainBlock();
//

// Many function calls

addBlockAfter(result);
Enter fullscreen mode Exit fullscreen mode

Right

var lastBlockchainBlock;

lastBlockchainBlock = findlastBlockchainBlock();
//...

// Many function calls 
// we should refactor them to minimize space
// between variable definition and usage

addBlockAfter(lastBlockchainBlock);
Enter fullscreen mode Exit fullscreen mode

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

Photo by KMA . on Unsplash


Code is like humor. When you have to explain it, it’s bad.

Cory House


This article is part of the CodeSmell Series.

Top comments (6)

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
mcsee profile image
Maxi Contieri

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!

Collapse
 
plaintextnerds profile image
Tim Armstrong

Cool, keep up the good work! I'll delete my comment.

Thread Thread
 
mcsee profile image
Maxi Contieri

There's no need. Thank YOU Tim!

Collapse
 
tudorhulban profile image
Tudor Hulban

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 :).

Collapse
 
mcsee profile image
Maxi Contieri

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