Examine code quality

Completed

Code quality shouldn't be measured by personal opinions. A developer writing code would rate their own code highly, but that's not a reliable way to measure code quality. Different teams may use different definitions based on what they're building.

Code that is considered high quality may mean one thing for a car software developer and something different for a web application developer.

Code quality is important because it affects the overall software quality.

A study on "Software Defect Origins and Removal Methods" found that individual programmers find less than 50% of bugs in their own software. Most forms of testing only find 35% of bugs. This makes it difficult to determine quality.

There are five key traits to measure for higher quality code:

Reliability

Reliability measures how likely a system is to run without failure over a specific period of time. It relates to the number of defects and availability of the software. You can measure several defects by running a static analysis tool.

Software availability can be measured using the mean time between failures (MTBF).

Low defect counts are crucial for developing reliable code.

Maintainability

Maintainability measures how easily software can be maintained. It relates to the code's size, consistency, structure, and complexity. Making sure source code is maintainable relies on several factors, such as testability and understandability.

You can't use a single metric to ensure maintainability.

Some metrics you may consider to improve maintainability are the number of style warnings and Halstead complexity measures.

Both automation and human reviewers are important for developing maintainable code.

Testability

Testability measures how well the software supports testing efforts. It depends on how well you can control, observe, isolate, and automate testing, among other factors.

Testability can be measured based on how many test cases you need to find potential faults in the system.

The size and complexity of the software can impact testability.

So, applying methods at the code level—such as cyclomatic complexity—can help you improve the testability of the component.

Portability

Portability measures how usable the same software is in different environments. It relates to platform independence.

There isn't a specific measure of portability. But there are several ways you can ensure portable code.

It's important to regularly test code on different platforms rather than waiting until the end of development.

It's also good to set your compiler warning levels as high as possible and use at least two compilers.

Following a coding standard also helps with portability.

Reusability

Reusability measures whether existing assets—such as code—can be used again.

Assets are more easily reused if they have modularity or loose coupling characteristics.

The number of interdependencies can measure reusability.

Running a static analyzer can help you identify these interdependencies.