Are we done on code smells? Probably never!
We see several symptoms and situations that make us doubt the quality of our development.
Let's look at some possible solutions.
Most of these smells are just hints of something that might be wrong. They are not rigid rules.
This is part V. Part I can be found here, Part II here, Part III is here, and Part IV here.
Let's continue...
Functions, lambdas, closures. So high order, nondeclarative, and hot.
Photo by Roman Mager on Unsplash
Closures and anonymous functions are very useful to model code blocks, promises etc. So It'd difficult to tear them apart.
Humans read code. Software works ok with anonymous functions but
maintainability is compromised when multiple closures are invoked.
Object-oriented programming increases the value of these metrics by
managing this complexity. The most effective tool available for dealing
with complexity is abstraction. Many types of abstraction can be used,
but encapsulation is the main form of abstraction by which complexity is
managed in object-oriented programming.
Rebecca Wirfs-Brock
Do you need help? Who are you gonna call?
Notice static methods.
Or we can make the former Helper stateless for reuse...
Code naming standards should forbid classes with this name on them.
This is a well established cultural name and a legacy habit from structured programming.
Most developers are reluctant to let old habits go.
We must be aware of the damage this kind of names are bringing us.
Do you check who are you talking to?
Photo by Remy Gieling on Unsplash
Since type checking methods are well known it is very easy to set up a code policy checking the uses.
Testing for a class type couples the objects with accidental decisions and violates bijection since no such control exists on real world. It is a smell our models are not good enough.
Booleans should be just True and False
This is a language feature. Some strict languages show warnings with this magic wizardry.
Some languages encourage doing some magic abbreviations and automatic castings. This is a source of errors and a Premature Optimization warning.
We should always be as explicit as possible.
It is not the language that makes programs appear simple. It is the programmer that make the language appear simple!
Robert Martin
Patterns are awesome. With great powers comes great responsibility
Photo by Nathan Dumlao on Unsplash
It would be very difficult to create automatic detection rules.
A class name with more than one pattern on it, is a warning.
Chose when to apply a pattern solution. You are not smarter for using too many patterns. You are smart if you choose the right opportunity for everyone.
When you have a hammer, every problem looks like a nail.
Will it be the end? Are we done? Guess not!