Comments are a code Smell. Getters are another code smell. Guess what?
TL;DR: Don't use getters. Don't comment getters
-
Comment Abusers
-
Readability
-
Getters
-
Remove getter comments
-
Remove getters
A few decades ago, we used to comment on every method. Even trivial ones
Comment should describe only a critical design decision.
contract Property {
int private price;
function getPrice() public view returns(int) {
/* returns the Price */
return price;
}
}
contract Property {
int private _price;
function price() public view returns(int) {
return _price;
}
}
[X] Semi-Automatic
We can detect if a method is a getter and has a comment.
The function needs a comment, that is accidentally a getter and the comment is related to a design decision
- Comments
Don't comment getters.
They add no real value and bloat your code.
Code Smell 05 - Comment Abusers
Photo by Reimond de Zuñiga on Unsplash
Code should be remarkably expressive to avoid most of the comments. There'll be a few exceptions, but we should see comments as a 'failure of expression' until proven wrong.
Robert Martin
Software Engineering Great Quotes
This article is part of the CodeSmell Series.