visit
Most of these smells are just hints of something that might be wrong. They are not rigid rules.
This is part II. Part I can be found here, Part III here, Part IV and Part V.
Image Source: on
Problems
Solutions
Examples
Exceptions
Sample Code
Wrong
Right
Detection
Automatic detection is possible in some languages. Watch some warnings related to complexity, bad names, post increment variables, etc.Also Known as
Conclusion
Too clever developers write cryptic code to brag. Smart developers write clean code. Clean beats clever, every time.Tags
Image Source: on
Problems
Solutions
If Boolean maps to a real-world entity it's safe. Otherwise model as a State to favor Extensibility. This also follows .Examples
Exceptions
Sample Code
Wrong
Right
Detection
Automatic detection can warn for boolean usage but this can yield false positives.Relations
Some languages have issues with boolean comparators.Also Known As
Tags
Conclusion
Take extra care when declaring something boolean. Flags are difficult to maintain and extend. Learn more about the domain or try migrating to . Use polymorphism instead of ifs/switch/cases.
Image Source: on
Problems
Solutions
Sample Code
Wrong
Right
Detection
Automatic detection is possible using parsing trees.Also Known As
Tags
Conclusion
Avoid successive message calls. Try to hide the intermediate collaborations and create new protocols.Image Source: on
Problems
Solutions
Examples
Exceptions
Avoid metaprogramming. When used it is very difficult to find references to the code.Laziness Chapter I: Meta-Programming
Sample Code
Wrong
Right
Detection
Coverage tools can find dead code (uncovered) if you have a great suite of tests.Tags
Conclusion
Remove dead code for simplicity. If you are uncertain of some code you can temporarily disable it using . Removing code is always more rewarding than adding.Image Source: on
Problems
Solutions
Exceptions
Sample Code
Wrong
Right
Detection
Most linters warn when the arguments list is too large.Tags
Conclusion
Relate similar arguments and group them. Always favor real-world mappings. Find in the real-world how to group the arguments in cohesive objects.If a function has too many arguments, some of them might be related to the class construction. This is a design smell too.That's all for now! More code smells coming soon!