Today we are going to take a look, and discuss on yet another code smell named “Comment”. Sounds like some thing is been told wrong, yes you guys heard right, comment is one kind of smell. The days of well documented code with comment are gone, now time has changed and new agile wind is flowing, as a result comments are now considered as code smell.
How Comment is smell?
Who would have thought that this day will ever come, I have worked with organizations where the developers is been given extra time to put right comment on code, but its history. How comment is smell? its simple the code is not self explanatory, so the code is smelly.
“The idea is to make each and every piece of code self explanatory.”
If your code need comment, you should take careful consideration to refactor your code so that it need no comment at all.
Some Useful Example
In bellow code what ever comment you are seeing is a comment smell.
Which comment is Allowed?
- In a function a algorithm is been implemented, for instance a tax calculation procedure, and the procedure is been implemented following a particular rule in a tax book. If you provide the name and reference of the book its not a comment.
- Class responsibility declaration, its okay to put few lines of comment above a class, and describe its purpose.
Its all about judgment
In the end a programmers judgment matters, we would know when to comment and where not to comment, with little refactor effort we can avoid comment.