Introduction to Code Quality
There is this joke around online that the real quality of code can be measured in what the per minute means—how many ‘What The ?’ experience another programmer has if he's looking at your code. The less what the experience he gets during checking your code, the better your code quality, and exactly about this topic I wanted to write the article today: Code Quality.
Hello and welcome or welcome back my name is Usman, and in today's article, I’m going to discuss the code quality. We will talk about what exactly code quality is, how we can measure it, and how we can decrease ‘What The ?’ per minute in our code if another programmer looks at it.
Before we can go any further, if you have any query on web development you can find me on LinkedIn, the link is below!
Muhammad Usman
The Importance of Units in Code Quality
Let's start with a simple topic: mathematics, size, and units play a great role in our everyday life. We often measure basic things like how fast is a car, how tall is a tree, how much weight did you gain during COVID-based home office, and so on.
In order to make such comparisons, we need something to measure things in our everyday life. We have meters, kilometers per hour, and so on. Because we have those measurements, we can say a Ferrari is faster than a Volkswagen, a Volkswagen is slower than a Lamborghini, and a Mercedes is more comfortable than a Toyota.
So the question is, if you want to measure code quality and not estimate it by our guts or rumors, how do we proceed? What is the unity of code quality, and what is our criteria to measure code quality? If we don't even know the unit of code quality, how can we even know if a modification to our software was better than before or even worse?
How to Measure Code Quality
First of all, to assess whether customer expectations are being met, quality metrics have to be used. For measuring and comparing code quality, we will need a quality model. A respected quality model is the ISO 25010.
The good message is that we have a standardization of what code quality is composed of. Let's take a look at the ISO model:
- The criteria on the right-hand side of the ISO model are external qualities. These can be experienced by the end user. For example, a user can experience how fast the programming is running on his desktop or smartphone. He can also experience the aesthetics of your website or graphical user interface, meaning if it looks beautiful and attractive or not.
- The criteria on the left side of the ISO model are internal qualities. Internal qualities mean that you and your co-workers or company have to deal with the code and can experience it in different ways. Let's look for example at maintainability. You or the company you work for can measure the reusability of your code. This means, can a code be still reused before you publish a big update, or are code parts not usable anymore and need to be rewritten?
Maintaining Code Quality
Are you able to keep the code clean and short with good documentation so that new programmers who join your project at some point can easily work with it, or is it a mess? Has the code been tested? Are there code smells, that code, or even hidden bugs?
These are, of course, simple examples, and you can dive much more into the topic, but that however would go beyond the scope of this article. The most important thing is that you get to know what code quality is and how you can measure it.
The Challenges in Measuring Code Quality
Let's now talk about the bad message on the ISO model. As you can see, there are still no questions answered on how to measure, what to measure, and what metrics to use to identify good or bad software. So we have to be a little more practical about it.
There is one general rule, quite similar to testing issues: it is always easier to find software defects like code smells, technical debt, security leaks, and in general, defects in your coding. Therefore, we focus more on measuring the lack of code quality than the actual code quality.
Metrics for Code Quality
Some units can be measured by a tool or formulas. For example, technical debt, code coverage for test cases, complexity, readability, performance, and maintainability. There are tools that can help you a lot to decrease ‘What The ?’ per minute if you're introducing your code to another programmer.
Please don't forget to like this article, and if you haven't already, follow me for future learning, because I’m bringing a lot of programming-related content regularly. If that's your thing, then definitely follow. For the rest, I wish you a wonderful day and have fun programming. Goodbye!
Top comments (0)