As I watched some of my fellow travellers absent mindedly throw garbage out of the window on a recent train journey, I struck a conversation with them to understand why cleanliness awareness campaigns haven’t had any impact on them. While I heard them defending themselves, it occurred to me that there is a striking similarity in the mindset behind littering our surroundings and in writing code which is not considered ‘clean’.
1. The area / code is already very messy, why bother?
“The streets and railway tracks are already littered with garbage and no one has cleaned it up; adding to the trash is not a problem.”
Similarly, people believe that a piece of code that does not have a good design or has duplication is already messed up. Hence, it is okay to not fix it and instead write substandard code. This is also known as the “Broken Window theory” (Ref : The Pragmatic Programmer). One broken window in a building that is left unrepaired will result in the inhabitants believing that no one cares. This will in turn result in another broken window, littering, graffiti and soon enough the clean building turns into an abandoned mess.
Don’t leave broken windows. Fix each one as soon as it is discovered. Similarly, don’t leave garbage lying around for very long. Clean it or get it cleaned immediately.
2. Someone else will clean it
“Sweepers are paid to clear garbage. It is okay to litter as there is someone to clean up after.”
Likewise, many a time we end up with a “tech debt monkey” in our teams who are the only people fixing these technical debts. We don’t think twice about making an entry in the “tech debt” sheet and leaving it to these “experts”.
All team members should be conscious of the fact that tech debt will hurt them eventually and hence strive not to create this debt. Even if there is any, they should, contribute in cleaning up the code.
3. Really? It’s just one paper / line of code!
“It’s just a small wrapper, throwing it outside the window will not add to littering”.
Similarly, a mindset of “it’s just these 2 lines of code which are messy, the rest is good” is just the start and will slowly spread and spoil the code.
“The trash can is too far away, I can’t go all the way to throw it”.
Similarly, we might believe that a certain code is not the best solution to a problem. But if the right way takes a lot more time and effort, we might compromise and use the quicker solution and postpone the better solution to later.
This anti-pattern almost always results in refactoring the necessary code which leads to more effort and requires a lot more time later. So, don’t take the shortcut, get your best possible code out at the first shot!
5. People are starving! What do you care about littering?
“There are bigger problems in life to solve than caring about our surroundings”.
Likewise, reasons like “this needs go to production” or “I need to get this story done today” are excuses we make which will ultimately hit us in the long run.
I have myself been a culprit of littering a couple of times. Just being aware of the consequences has made me think twice and prevented me both from throwing waste in a public area and also keeping my code as clean as possible.
Let us strive to keep our environment and code litter free!