Smell of the symbol 287 – an unused local mission
Do you use the returned value?
TL; DR: Avoid setting values that you never use.
problems
Solutions
- Remove unused tasks.
- Try to avoid side effects.
Context
When you set a value to Local variable But never use it, you can create unnecessary chaos in your code.
This can mix between others and make the code more difficult to maintain it.
Sometimes, when correcting errors, you can set time variables for a better examination.
This also happens when the implementation is set to The object feature But it is difficult to follow.
It is also a sign of a museum because if you remove the task, it will only remain the side effects.
Mutlaws can cause unexpected side effects, making it difficult to track changes.
Code model
mistake
function updateUserName(user, newname) {
user.name = newname;
return user;
}
function performMaintenance(existingUser) {
let updatedUser = updateUserName(existingUser, "Bobby Peru");
// Other tasks
}
// The variable updatedUser is never used
right
function updateUserName(user, newname) {
user.name = newname;
// Just side effects without explicit return
}
function performMaintenance(existingUser) {
updateUserName(existingUser, "Bobby Peru");
// Other tasks
}
a statement
You can discover this smell using fixed analysis tools or code reviews that check unused variables after customization.
Most of this science pesticides as an issue.
level
Why is the important objection
It remains clean and effective when the code accurately reflects the logic of the real world.
The unused tasks break this connection, making it difficult to understand the intention and maintain the symbol.
AI generation
Artificial intelligence tools rarely create unused variable tasks when they misunderstand the intention.
Discover artificial intelligence
The AI’s help with clear instructions can indicate the formation of unused variables and suggest removal processes, but it may not always understand whether the return value should be used.
Try them!
Remember: Artificial Intelligence Assistants make many mistakes
conclusion
Unused variables after mutations create noise and confusion.
Do not help the return value if you do not need it.
If the method should restore something meaningful, make sure to use it.
Relations
More information
Disintegration
The smell of the code is my opinion.
Credits
Photography by Ivan Demekoli
If you have to make efforts to decipher the symbol, you must rewrite it.
Martin Golding
This article is part of the Codesmell series.