Code Smell 75 — Comments Inside a Method
Comments are often a code smell. Inserting them inside a method calls for an urgent refactor.
Comments are often a code smell. Inserting them inside a method calls for an urgent refactor.
TL;DR Don’t add comments inside your methods. Extract them and leave declarative comments just for not obvious design decisions.
Problems
Readability
Kiss
Low Reuse
Bad Documentation
Solutions
1. Extract Method
2. Refactor
3. Remove not declarative comments.
Sample Code
Wrong
Right
Detection
This is a policy smell. Every linter can detect comments not in the first line and warn us.
Tags
Readability
Long Methods
Comments
Conclusion
Comments are a code smell. If you need to document a design decision, you should do it before the actual method code.
Relations
Code Smell 03 — Functions Are Too Long
Humans get bored beyond line 10.blog.devgenius.io
Code Smell 74 — Empty Lines
blog.devgenius.io
Code Smell 05 — Comment Abusers
Code has lots of comments. Comments are coupled to implementation and hardly maintained.blog.devgenius.io
Don’t get suckered in by the comments, they can be terribly misleading: Debug only the code.
Dave Storer
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


