According to Robert C. Martin, author of Clean Code: A Handbook of Agile Software Craftsmanship:
Writing clean code is what you must do in order to call yourself a professional. There is no reasonable excuse for doing anything less than your best.
But what does "clean code" mean?
As Robert C. Martin mentions in his book, many authors have their own definitions of clean code. However, most of them mention at least one of these characteristics:
- Easy to read
- Easy to understand
- Easy to change
To this end, the code must be simple, tidy, and have the right abstractions. It is necessary to spend time reviewing the code to find ways to improve it and achieve a clean code.
The code review
In the code review, we can find many improvements such as more meaningful variable names, splitting long methods into smaller ones, reorganizing code into more specific classes, and so on. Of course, this can take time. But that investment of time will pay off every time you or your co-workers refer back to the code. It will be easy to read, understand and change.
As a result of the code review, we would deliver a polished and refined code. Our co-workers would appreciate it and we would convey the culture of clean code also. When others see that elegant and tidy code, no one will want to be the first to screw it up.
Reasons why we don't write clean code
Let's be honest. Sometimes, we forget to review the code or just leave it for later refactoring. That code can even stay there forever, though. There is a famous saying:
Later equals never
As developers, we commit to complete a certain amount of work. We have deadlines, that unconsciously lead us to code as quickly as possible, leaving aside the code review and consecutively the code quality.
Follow @gitlost on Twitter for more funny git commit messages.
We could go on citing reasons why we don't write clean code, such as the code was already a mess before it passed through our hands, as mentioned by Andy Hunt and Dave Thomas in The Pragmatic Programmer, making an analogy with the broken windows theory. You can find more information about this theory in this article.
It turns out that, as professionals, we should not look for excuses but solutions. If something is not right, we must be able to communicate it and provide solutions. Otherwise, we would be part of the mess. So, the main reason we don't write clean code is that we are not professionals.
Spending time on code review is the key to clean code and can make the difference between being a professional developer or not. A professional not only cares about the code does what it is expected to do but also cares about the quality of the code.
So the next time you are about to push your changes, I invite you to take a look at your code and ask yourself the following questions:
- Am I satisfied with this code?
- Does this code represent me as a programmer?
If the answer is no, I invite you to spend some time reviewing your code and finding ways to improve it.
So, are you a professional developer?
Thanks for reading!