Yet more code smells? Aren't them enough?
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, Part IV here, part V, VI, VII and the last one (for now).
Let's continue...
RegEx are a wonderful tool, we should to use them carefully and not to look smart.
Photo by John Jennings on Unsplash
Wrong
Right
Regular expressions are a valid tool. There's not much automated way of checking for possible abusers. A whitelist might be of help.
Regular expressions are a great tool for string validation. We must use them in a declarative way and just for strings.
Names are very important to understand pattern meanings.
If we need to manipulate objects or hierarchies, we should do it in an object way.
Unless we have a conclusive benchmark of impressive performance improvement.
What Exactly Is A Name: The Quest [Part I]
A Perl program is correct if it gets the job done before your boss fires you.
Larry Wall
Compilers and warnings lights are there for help. Don't ignore them.
Photo by Noah Dominic Silvio on Unsplash
Wrong
Right
Most languages have warning levels. We should turn most of them ON.
We should run linters to statically analyze our code for potential problems.
If we ignore warnings and the code moves on sooner or later it will fail.
If the software fails later it will be very difficult for us to find root cause.
Defect will likely be near first warning and far away from the crash.
If we follow the Broken Windows Theory, we should not tolerate any warnings, so a new issue will not pass unnoticed in a sea of tolerated warnings.
One man's crappy software is another man's full time job.
Jessica Gaston
Inheritance. Concrete classes. Reuse. A fantastic mix up.
Wrong
Right
Overriding a concrete method is a clear smell. We can enforce these policies on most linters.
Abstract classes should have just a few concrete methods. We can check against a predefined threshold for offenders.
Accidental sub-classification is the first obvious advantage for junior developers.
More mature ones find composition opportunities instead.
Composition is dynamic, multiple, pluggable, more testable, more maintainable and less coupled than inheritance.
Only sub-classify an entity if it follows the relationships behaves like.
After sub-classing the parent class should be abstract.
Software is a gas; it expands to fill its container.
Nathan Myhrvold
Compilers are smarter than us. On a Friday night production deploy they betray us.
Photo by Senor Sosa on Unsplash
Wrong
Right
Many of this vicious are encouraged by languages themselves.
We should be very declarative and explicit and don't abuse language accidental magic solutions.
Programmers pretend to be smart by exploiting language features.
They feel they belong to community standards that enforce bad behaviors like a sect.
Hackers are arrogant geek romantics. They lack the attentive spirit of inquiry.
Bruce Sterling
Methods should be interchangeable if they do the same.
How to Get Rid of Annoying IFs Forever
Wrong
Right
This is a semantic mistake. We could add a warning for similar method names on Polymorphic classes.
Naming is very important. We need to name after concepts and not after accidental types.
If you have three pet dogs, give them names. If you have 10,000 head of cattle, don't bother. Nowadays, the idea of giving a name to every file on your computer is ridiculous.
David Gelernter
We are done for now. But we are pretty sure we will come across even more smells very soon!
I keep getting more suggestions on twitter, so they won't be the last!