The code smells bad. Let’s see how to change the aromas. In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most of these smells are just hints of something that might be wrong. They are not rigid rules.
Your objects are a bunch of public attributes without behavior.
Photo by Stacey Vandergriff on Unsplash
Protocol is empty (with setters/getters).
If we ask a domain expert to describe an entity he/she would hardly tell it is ‘a bunch of attributes’.
Detection can be automated with sophisticated linters ignoring setters and getters and counting real behavior methods.
A method makes calculations with lots of numbers without describing their semantics.
Photo by Kristopher Roller on Unsplash
Many linters can detect number literal in attributes and methods.
Humans get bored beyond line 10.
Photo by Hari Panicker on Unsplash
All linters can measure and warn when methods are larger than a predefined threshold.
Too many parsing, exploding, regex, strcomp, strpos and string manipulation functions.
Photo by Nathaniel Shuman on Unsplash
Automated detection is not easy. A warning can be issued if too many string functions are used.
Code has lots of comments. Comments are coupled to implementation and hardly maintained.
Photo by Volodymyr Hryshchenko on Unsplash
Linters can detect comments and check the ratio comments / lines of code against a predefined threshold.
… and many more to come.
Smells are certain structures in the code that suggest (sometimes they scream for) the possibility of refactoring.
Martin Fowler
Part of the objective of this series of articles is to generate spaces for debate and discussion on software design.
We look forward to comments and suggestions on this article.