As a developer who constantly strives to write readable, coherent and generally good code I’m always on the lookout for practices that can boost the quality of source. In this post I’d like to share with you one that I have used for a long time and so far has benefited me the most.
Read every line of code before you commit it.
It seems a bit too simplistic, right? How can this practice improve the quality of your code? Think about it for a second – what does it actually mean. Essentially you are doing yourself a code review. Some people might doubt it’s effectiveness because the creator is always biased towards his own creation. I agree with that. However if you start applying it you will be astonished how many undesirable lines of code slip into your codebase. Maybe you have misspelled a name, forgot to update a comment, have unused variable or some inconsistency in your refactoring. All these little things add up rapidly and this way of work is really good at handling them at the earliest stage before anyone else has even seen them. And as always…
There’s a catch.
The number one reason few people are using this method is that it’s not a tool or some script. Unlike a static analyzer it won’t find the mistakes for you. The developer is personally liable for reviewing each line and this naturally requires some commitment. It may take some time to get used to but I found it to be a great practice, independent of what language or version control are used. So next time you stage your files for commit take a quick look at each change and I’m sure you will find something that could be bettered.