This article was originally published at medium.com ⬈
It is not that dirty code produces global warming, but the same behavior that drives towards global warming also drives towards dirty code.
Some days ago I have seen this video:
In this video, Robert C. Martin explains how a beautiful clean code gets rot until it becomes a complete mess. He warns that, with time, if we do not keep the code clean, the code gets messier. Each iteration delivers less value, and eventually, costs rise, and the project almost freezes. He is not the only one doing this warning; I have listened and read about it everywhere. His book, Clean Code, is considered one of the books that every developer should read. But for some reason, people are still delivering Dirty Code. It looks like Global Warming, everyone knows that we have to change our behavior, but nobody does any significant step.
What drives us to Global Warming? There is no immediate reward for solving Global Warming. It is even worse; if you try to fight it, you pay the price twice. First, we pray for longer commuter times, more expensive products, and many other examples. If we change the windows of our home, we can save some bucks in ten years, but today it is cheaper to pay more for energy. The second is that we need others to follow us. If we pay the effort of making the changes, but nobody else does, we pay double. Today we pay the price of trying to change something, and tomorrow we pay the cost of fighting global warming.
What drives us to Dirty Code? The same two main inconveniences. First; at any company, there is a reward for those who finish their features more quickly. It can be explicit or implicit; a simple "well done" or pointing out that the ratio of implemented points under an arbitrary expectation is enough. If you decide to clean the code, build better tests, refactor small pieces to ensure a smooth system, you have to give some explanation. You pay the price. Second; in the future, if others do not clean the code, you suffer the consequences. Everyone gets slower, and no one would be faster than others. Everyone would pay the cost of fighting Dirty Code.
The same human behavior drives both, Global Warming and Dirty Code. There is a short term reward to move in the wrong direction. And there is also a consequence of collective behavior.
Both are cases of the Tragedy of the commons. It is a situation in a shared-resource system where individual users act independently according to their self-interest and behave contrary to the common good of all users by depleting or spoiling the shared resource through their collective action.
The Global Warming is slow, and it takes generations to see the effects. It started more than one hundred years ago. But Dirty Code effects are fast. In just two years, it ruins any project with high costs and lots of bugs. The most disturbing fact is that you can be in the middle of a ruined project because of Dirty Code and do not see it.
Is there any solution to Dirty Code? This question is equivalent to: Can we force anyone to work for the common good? There are some solutions in the Tragedy of the commons. In computer software we have agile. Agile defines a framework to measure progress, some implementations say points, but it is not a target metric. It is a source metric. You can use it to estimate the future, but not to evaluate progress.
Do not create short-time rewards based on delivered features.