Metrics are everything in business. Metrics like the number of customers, revenue per customer, total revenue, costs and profits are commonly used to measure business health. A challenge for many businesses is determining what set of metrics can measure success — or failure — in software development. A common metric referenced is the number of lines of code written or reviewed per hour. This is an easy metric to calculate, but it does not tell the whole story. In fact, it may tell the wrong story.
More lines of code do not necessarily result in software that is efficient, understandable, and scalable. To measure properly the overall efficacy and quality of code requires using code quality metrics other than the number of lines of code.
Three Steps to Better Code Quality Metrics
Step One: Use Stories to Anchor Agile Code Review
Determining stories in the code review process can orient developers and business leader’s path towards determining and implementing better code quality metrics.
Code reviews leverage the advantage of Agile as a software development methodology, in that the project is broken down into stories. In turn, the code is also correlated to the stories. This correlation allows the business stakeholders to review the logic of the code with the developers even if they don’t know how to write code. It also allows other developers to review the code for coding best practices. Both the business stakeholders and the developers should have either formal measurements for code quality metrics or at least an idea of what they are going to look for in the coding to determine its quality.
Business stakeholders can ask some of the following questions to anchor their code review process:
- Are the variables understandable (“zipcode” vs. “zc”)?
- Does the code consider all options (US and Canadian Zip Codes)?
- Does the flow of the logic follow the validation and work flows as you understand them?
A business stakeholder may not understand the idiosyncrasies of the programming language, but they should still be able to follow the flow of the code. For developers, identifying common coding mistakes, code maintainability, scalability and intersection points with other systems and other pieces of code are areas of concern.
Step Two: Manual Testing Improves Code Quality Metrics
Manual testing is the most common form of testing software as it is the easiest to understand and quickest to implement. The developers produce some code, and someone tries the code to see if the desired results are obtained. Easy enough.
But manual testing can be inconsistent and difficult to scale. As the system gets larger, it takes more time to test the entire system manually. Determining code quality metrics through manual testing is also a challenge since a tester’s tolerance and documentation of defects may also vary.
Step Three: Test Automation
Setting up automated tests requires more time upfront than manual tests, but restore velocity over time as the tests are repeated for each sprint or release. Repeated testing (regression testing) performs much faster and more accurately than manual testing. Automated testing documents errors automatically and allows the team to understand if it is using the proper code quality metrics to test the software in question.
Why Defining Goals Improves Your Code Quality Metrics
Prior to the start of a project, a best practice is to develop what coding standards and code quality metrics will anchor and indicate success for your project. There are dozens of resources online that cover code review practices, which teams can tailor to the needs of their own projects. Determining a central set of code quality metrics at the start of a project holds everyone accountable and will improve the quality of the work.
Agile development lends itself to starting small. Code reviews can cover a slice of code within a larger software story. Manual testing tests the code against the story to determine if the requirements are delivered. Blending manual processes with test automation early in the project help to break the code quality metrics into manageable chunks. By starting small, a team can develop logical processes and share code quality metrics more easily along the way. When new features are added to a product, relevant tests developed along the way can test these new functionalities as needed.
Customize Code Review Strategically
Code quality metrics can take on many forms. It’s important to understand the nature of your software development strategy so that you can tailor your approaches to code review, manual and automated testing to maximize your code quality metrics. Implementing all three legs of code testing gives teams the best of both worlds: the speed of Agile driven by exacting quality.
Image Source: Unsplash, Chunlea