Code Smell 183 — Obsolete Comments
Comments are a code smell. Obsolete comments are a real danger and nobody maintains what can’t be executed.
Comments are a code smell. Obsolete comments are a real danger and nobody maintains what can’t be executed.
TL;DR: Don’t trust comments. They are dead.
Problems
Bad documentation
Maintainability
Solutions
Replace comments with tests
Refactorings
Refactoring 005 — Replace Comment with Function Name
Comments should add value. And function names too.levelup.gitconnected.com
Context
We know comments add almost no value to our code.
We need to restrict comments only to very important decisions.
Since most people change logic and forget to update comments they might become obsolete easily.
Sample Code
Wrong
void Widget::displayPlugin(Unit* unit)
{
// TODO the Plugin will be modified soon,
// so I don't implement this right now
if (!isVisible) {
// hide all widgets
return;
}
}Right
void Widget::displayPlugin(Unit* unit)
{
if (!isVisible) {
return;
}
}Detection
[X] Semi-Automatic
We can warn for comments in our code and try to remove them.
Exceptions
Very important design decisions
Tags
Comments
Conclusion
We need to think before adding a comment. Once It is in the codebase is beyond our control and can start to lie anytime.
Relations
Code Smell 05 — Comment Abusers
Code has lots of comments. Comments are coupled to implementation and hardly maintained.blog.devgenius.io
Code Smell 152 — Logical Comment
Temporary hacks might be permanentlevelup.gitconnected.com
Code Smell 151 — Commented Code
Beginners are afraid to remove code. And many seniors too.levelup.gitconnected.com
Disclaimer
Code Smells are just my opinion.
Credits
Photo by Volodymyr Hryshchenko on Unsplash
Obsolete comments tend to migrate away from the code they once described. They become floating islands of irrelevance and misdirection in the code.
Bob Martin
Software Engineering Great Quotes
Sometimes a short thought can bring amazing ideas.blog.devgenius.io
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
The code smells bad. Let’s see how to change the aromas.blog.devgenius.io


