DEV Community

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

Posted on • Originally published at

Code Smell 81 - Result

result = ???

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


  • Readability


  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


var result;

result = lastBlockchainBlock();

// Many function calls

Enter fullscreen mode Exit fullscreen mode


var lastBlockchainBlock;

lastBlockchainBlock = findlastBlockchainBlock();

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

Enter fullscreen mode Exit fullscreen mode


We must forbid the word result to be a variable name.


  • Readability


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.


More info


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)

Sloan, the sloth mascot
Comment deleted
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!

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!

tudorhulban profile image
Tudor Hulban

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

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