There is a famous quote – “Any fool can write a code that computer can understand. Good programmers write code that humans can understand”. Any idea what does it transpire to, doesn’t it mean that writing a code is one thing but writing a clean code is taking it to another level.
A good programmer should know how to write a clean code that can be understood by others too, not only himself. Good code can be beneficial for an organization but bad code can destroy it.
Robert Martin an american software engineer and author, wrote in his book named “Clean Code” the only valid measurement of code quality is the number of WTFs per minute while reviewing the code. Picture below is taken from the same book :
Martin further writes : Which door represents your code? Which door represents your team or your company? Why are we in that room? Is this just a normal code review or have we found a stream of horrible problems shortly after going live? Are we debugging in a panic, poring over code that we thought worked? Are customers leaving in droves and managers breathing down our necks? How can we make sure we wind up behind the right door when the going gets tough? The answer is: craftsmanship.
Their are infamous examples of bad code which caused lot of damage to companies . There is a great example such as space rockets being mislaunched due to a badly transcribed formula (a single line was missing that meant the rocket had to be terminated 293 seconds after launch ultimately costing around 20 million dollars) or take an example of bug in radiation therapy machine called Theract-25 which involved in at least six accidents between 1985 and 1987, in which patients were given massive overdoses of radiation. Why? Because of concurrent programming errors, it sometimes gave its patients radiation doses that were hundreds of times greater than normal, resulting in death or serious injury. This was a side effect of the buggy software powering the device. You can read more about it here.
A good quality code is highly important for stability and maintainability of a product or a system. Like a normal nature in any project / product, as new features are added or functionality is updated you encounter that a new developer or an entire new team working on the codebase. There is high possibility that earlier developer may not be anymore with organization or completely forgot the flow and details of the project. In such case if the quality of the code is not upto the mark, then adding complexity to the project is inevitable adding to the more salt to injury.
Below pictures shows how much a programmer’s time spent in coding –
If you observe closely at the chart you will understand where does the maximum time goes, does it go in writing the new piece of code? No. It basically goes in either fixing/modifying an existing code or understanding the code itself.
That’s why a good programmers considers themselves as someone who is writing a book which is readable. Remember the intended audience is not the computer, it is other programmers (and yourself worst case). You are constantly reading old code in order to write new code.
Writing clean code is essential and critical, since it is maintainable, stable and easy to understand for any future developer.
“Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program. “ – Linus Torvalds
Few quotes from Martin’s book of clean code –
- “Later equals never.”
- The only way to make the deadline , the only to go fast – is to keep the code as clean as possible all times.
- Clean code always look like as if it was written by someone who cares.