Skip to main navigation Skip to search Skip to main content

Complementarity in software code complexity metrics

  • Gao Hao
  • , Haytham Hijazi
  • , Júlio Medeiros
  • , João Durães
  • , Chan Tong Lam
  • , Paulo De Carvalho
  • , Henrique Madeira
  • University of Coimbra
  • Southwest Forestry University
  • Polytechnic Institute of Coimbra

Research output: Contribution to journalArticlepeer-review

3 Citations (Scopus)

Abstract

Despite the widely accepted notion that software metrics like classic McCabe cyclomatic complexity (V(g)) or those provided by tools such as SonarQube (CC Sonar) represent code understandability from the perspective of a typical programmer, the accuracy of these metrics in reflecting perceived code understandability remains uncertain. This paper investigates the complementarity of code complexity metrics using a data-driven approach that incorporates linear and non-linear regression models. To evaluate the complementarity of code metrics, a controlled experiment was conducted with 35 programmers of varying expertise, who read and comprehended a set of programs with varying levels of complexity. The complexity of the programs was initially measured using established metrics, and the cognitive load (CL) of the programmers was captured through electroencephalography (EEG) while they understood the code. Given the controlled conditions of the experiment (free from interruptions or distractions), the cognitive load measured by EEG accurately indicates the mental effort involved in understanding the code. The study found that Halstead metrics (Effort and Difficulty) have a higher correlation with EEG-measured cognitive load (Spearman correlation rs=0.66 and 0.64, respectively) compared to V(g) (rs=0.33) and CC Sonar (rs=0.35). However, no single metric fully captured the complexity perceived by programmers, emphasizing the need for complementary metrics. The results of combining multiple metrics through data-driven regression models significantly improved predictive accuracy, with Gaussian Process Regression achieving a maximum R² of 0.8742. These findings suggest that bridging the gap between static complexity metrics and the cognitive demands of code comprehension requires a hybrid approach that integrates complementary metrics, offering a more holistic view of code understandability.

Original languageEnglish
Article number112679
JournalJournal of Systems and Software
Volume232
DOIs
Publication statusPublished - Feb 2026

Keywords

  • Code complexity metrics
  • Cognitive load
  • EEG
  • Software quality

Fingerprint

Dive into the research topics of 'Complementarity in software code complexity metrics'. Together they form a unique fingerprint.

Cite this