Does code quality matter? How much does it matter? In your day-to-day coding, how much time and energy should you spend worrying about code quality?
To begin with, what exactly is code quality? On this matter, there is definitely a host of both vague and well-defined criteria for what code quality exactly is. There are machine calculable criteria, such as cyclomatic complexity and similar measures, as well as more subjective measures. I believe though, that the idea of code quality can be adequately condensed down to one succinct point: Code readability. The entire point of code quality is for readability. This is the result we're seeking when we worry about and work to improve the quality of our code. We're trying to increase its readability. So quality code is readable code and vice versa.
Now that we know what it is, we can return to our original question. Does code quality help? Does it matter?
The very definition we came up with helps us begin to answer that question: readability. What is the benefit of readable code? Readability allows us to more effectively create mental models of the code we're reading. It's these mental models we have that allow us to write/modify our code. We must have a mental model (accurate or not) in order to write code. Without a mental model, we can only make random changes, like a chimp on a typewriter.
So where do our mental models come from? Here, there are two distinct answers. When first writing code, the mental model starts in our head and is then put into code. But when maintaining and modifying code written by others, or by us some time ago (possibly last year, possibly this morning), then the flow is that we must read the code, then create our mental model, and then we can change the code.
So code quality (readability) becomes very important as we do the second activity of reading code to modify it.
How much time do we really spend reading code then? "Indeed, the ratio of time spent reading versus writing is well over 10 to 1. We are constantly reading old code as part of the effort to write new code. …[Therefore,] making it easy to read makes it easier to write." ― Robert C. Martin.
Ten to One! Suddenly code quality emerges as a critical concern. Unfortunately, I believe in most cases, code quality is the third priority as we develop, falling after correctness and then time constraints/deadlines.
Code quality can, therefore, be seen as a very important concern. Something that does matter a great deal. I personally built a great deal of my career upon code quality, which is not to say that I believe that I am particularly good at writing highly readable code, only that I truly care about the practice and that I constantly seek to improve at this skill.
If quality isn't a very big concern of yours in your current job, I encourage you to rethink this and make changes to increase its priority in the code you write. In the future, I'll talk about ways to improve your code quality, but for now, leave with this simple encouragement: code quality matters! Don't leave it behind in the race to meet your deadlines.
Happy Coding!
Enjoy this discussion? Sign up for our newsletter here.
Visit Us: thinkster.io | Facebook: @gothinkster | Twitter: @gothinkster
Top comments (1)
Very nice post. Indeed code quality definitely matters for readability. There are many more reasons too.
Depending on code quality, adding additional features or even fixing bugs can be anywhere from easy to impossible. I've heard of more than one commercial project that's just not able to make any change at all. So code quality also requires good abstractions and separation of concerns.
Another way I would summarise it is:
Code is written for people to work with, not computers. If it was written for computers we would write in binary. Since code quality benefits humans, do we want it to be good and easy to work with or a mess and difficult to work with?