Why the first instruction we learn to program should be the last to use.
Nobody uses GOTO instruction anymore and few programming languages still support it.
We have matured and confirmed spaghetti code is unmaintainable and error prone. Structured Programming solved that problem years ago.
We got rid of the sentence thanks to Edsger Dijkstra’s incredible paper: Go To Statement Considered Harmful.
Next evolution step will be removing most IF statements
IFs/Cases and Switches are GOTOs disguised as structured flow.
Our tool will be Object Oriented Programming principles.
Incomplete objects cause lots of issues.
Any linter can warn this (possible) situation.
Always create complete objects. Make their essence immutable to endure through time. Every object needs its essence to be a valid one since inception.
Writing a class without its contract would be similar to producing an engineering component (electrical circuit, VLSI (Very Large Scale Integration) chip, bridge, engine…) without a spec. …
In this serie 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 clues of something that might be wrong. They are not rigid rules.
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’.
1) Find Responsibilities.
2) Protect your attributes.
3) Hide implementations.
4) Delegate
Detection can be automated with sophisticated linters ignoring setters and getters and counting real behavior methods.
This article is part of the CodeSmell Series. …
We can instruct our static linters to find wrapping methods if they follow conventions like doXXX(), basicXX() etc.
We came across this kind of methods some time in our developer life, We smelled something was not OK with them. Now is the time to change them!
The primary disadvantage of Wrap Method is that it can lead to poor names. …
Searching for a concrete method implementation? Go back and forth, up and down.
Any linter can check for suspects against a max depth threshold.
Many novice programmers reuse code through hierarchies. This brings high coupled and low cohesive hierarchies.
Johnson and Foote established in their paper this was actually a good design recipe back in 1988. We have learned a lot from there.
We must refactor and flatten those classes.
An error arises from treating object variables (instance variables) as if they were data attributes and then creating your hierarchy based on shared attributes. …
We can add automatic rules to find versioned methods with patterns.
Like many other patters we might create an internal policy and communicate.
Time and code evolution management is always present in software development. Luckily nowadays we have mature tools to address this problem.
That’s why I write, because life never works except in retrospect. You can’t control life, at least you can control your version.
Chuck Palahniuk
This article is part of the CodeSmell Series. …
“Hello World” is the first program me make in every language.
We can measure the complexity of language by counting the lines it takes to produce the desired output.
We can also time how much does it take to a newbie to figure out the solution (this is also known as Time to hello world” (TTHW).
These two metrics are uncorrelated to productivity.
Many sites compile different Hello World programs in a lot of languages.
The Hello Word example has a lot of problems introduced early when developers are making their first steps in programming.
We want our code to behave different on different environments, operating systems, so taking decisions at compile time is the best decision, isn’t it?.
This is a syntactic directive promoted by several languages, therefore it is easy to detect and replace with real behavior.
Adding an extra layer of complexity makes debugging very difficult. This technique was used when memory and CPU were scarce. …
You can set your linters to warn you for public attributes, setters and getters usage and discourage them.
If your classes are polluted with setters, getters and public methods you will certainly have ways to couple to their accidental implementation.
A data structure is just a stupid programming language.
Bill Gosper
This article is part of the CodeSmell Series.
About