Diving into Code Quality: Measuring Code Quality

    Nick Ferrara

    The first installment in this series, Diving into Code Quality: Factors Affecting Code Quality, discussed the factors which contribute to software code quality. Part 1 considered how poor code quality can contribute to failures of software development and implementation projects. In this installment, we discuss tools and techniques utilized by experts to measure code quality.

    Software Code Comparison Expert Witnesses on Measuring Code Quality

    A software expert witness usually chooses an appropriate methodology and corresponding technical tools to measure code quality based on the size and complexity of the software under examination.

    For large, complicated programs, experts usually choose to perform a code audit service or code quality analysis using automated tools, which can help identify defective code, security vulnerabilities, and code maintainability issues, and which may provide insight into the code’s architecture and dependencies.

    Automated tools also allow experts to examine software for adherence to coding best practices or to coding conventions followed by a development team.

    After reviewing results generated by an automated tool, an expert may manually review sections of code which appear worthy of further investigation.

    For small, less complicated programs, or for disputes which hinge entirely on no more than a few small modules of code, experts may forego the use of automated tools and conduct their analysis entirely based on manual review.

    Most software failure experts use both automated tools and manual review to assess code quality.

    Though there are numerous quantitative metrics that may be considered, some of the metrics software project failure expert witnesses typically consider in assessing code quality include code complexity, technical debt, code duplication, and coupling. 

    • Code Complexity

    Code complexity is a measure of how easy code is to understand and maintain. For example, smaller blocks of code containing a small amount of functionality are easier to understand and maintain than larger blocks of code containing a large amount of functionality.

    Further, complicated code which uses many different looping or nesting structures increases code complexity and can contribute to poor code quality.

    • Code Duplication

    Code duplication refers to similar or identical sections of reused or refactored source code. Code duplication can reduce maintainability and increase time needed to modify functionality if the same section of code must be modified in multiple parts of a program. However, academic research suggests that code duplication can be used as a valid engineering tool that, given the proper context, can improve maintainability. Thus, code duplication may indicate poor code quality under certain contexts, and may indicate higher quality in other contexts.

    However, a developer may decide to use duplicate code in cases where it improves code readability, with a tradeoff of reduced maintainability.

    Removing duplicate code with the help of a code comparison tool and functionality into reusable methods or classes that can be called upon when needed (e.g., by inheritance from a superclass, via utility methods) can eliminate or at least reduce instances of code duplication.

    • Coupling

    Coupling is a measure of interdependence between sections of code. Two distinct sections of code are said to be “tightly coupled” when changes in one section of code necessitates changes in the other.

    Modification of tightly coupled code may affect functionality in unintended ways and impact how well the program functions as a whole, which can contribute to poor code quality.

    On the other hand, in two distinct sections of code that are “loosely coupled,” one section of code may be changed with little to no impact on the other.

    Loosely coupled code allows for easier modification of a program’s architecture with minimal impact, creating easily interchangeable parts in the source code that are easier to maintain. Thus, loosely coupled code generally indicates high code quality.

    • Technical Debt

    Technical debt describes an estimation of the implied cost of rework caused by developers writing poor quality source code in the short-term to solve a problem, instead of writing high-quality source code in the first place.

    High levels of unaddressed technical debt over time can impact maintainability and can lead to poor code quality.

    Attorneys litigating software failure matters often find that DisputeSoft’s software source code analysis expert witnesses  significantly inform their understanding of a dispute.

    To learn more about the services we provide as software failure experts, please don’t hesitate to contact us at [email protected].

    Read the first installment: Diving into Code Quality: Factors Affecting Code Quality

    Read about DisputeSoft’s software project failure services.

     

     

    The views given here are the author’s alone, and do not necessarily represent the views of other DisputeSoft experts.