It’s tempting to try to measure code quality. And, to be fair, there is often a correlation between various metrics we’ve devised and the

Quality-of-code metrics are meant to be used as a guide, not as a set of objectives.

submited by
Style Pass
2021-05-18 07:34:44

It’s tempting to try to measure code quality. And, to be fair, there is often a correlation between various metrics we’ve devised and the actual quality of code.

However, it’s a mistake to use the numbers to declare your code’s quality absolutely. Instead, use code quality metrics as a guide to shine a light on opportunities for improvement.

Let’s take code coverage as an example. When running your automated tests, your code is instrumented so we can tell which lines or branches are executed. The idea: the closer you get to 100% coverage, the more thoroughly your tests are exercising your code.

That number can be quite useful. But if a team is gating the act of shipping code by requiring developers to stay over a threshold, you can quite easily encourage bad practices.

Let’s also say our standard is 90% test coverage. And our developers, who are supposed to be using test-driven development… aren’t. So they’re writing the tests after the fact, and they’re not very good:

Leave a Comment