Early Career Developers' Perceptions of Code Understandability. A Study of Complexity Metrics
Matteo Esposito, Andrea Janes, Terhi Kilamo, Valentina Lenarduzzi
TL;DR
The paper investigates whether two complexity metrics, McCabe Cyclomatic Complexity ($\text{CyC}$) and Cognitive Complexity ($\text{CoC}$), predict early-career developers' perceived code understandability and problem severity. Using an empirical study with 216 junior Java developers who evaluated 12 Apache-derived Java classes, the authors measured CyC and CoC with SonarQube and analyzed correlations with perceived understandability and severity via Spearman's $\rho$. They report modest negative correlations ($\rho$ around -0.38 for CyC and -0.33 for CoC with understandability) and weaker negative correlations with severity ($\rho$ around -0.27 for CyC and -0.17 for CoC), indicating these metrics are not strong indicators of understandability or problem severity for early-career developers. The study emphasizes that junior developers should not bear code-review responsibilities alone and suggests training and collaborative review practices; it also calls for replication with experienced developers, additional languages, and varied datasets. Overall, the work highlights the nuanced relationship between static complexity metrics and human perceptions of code understandability, guiding future validation and tool development.
Abstract
Context. Code understandability is fundamental. Developers need to understand the code they are modifying clearly. A low understandability can increase the amount of coding effort, and misinterpreting code impacts the entire development process. Ideally, developers should write clear and understandable code with the least effort. Aim. Our work investigates whether the McCabe Cyclomatic Complexity or the Cognitive Complexity can be a good predictor for the developers' perceived code understandability to understand which of the two complexities can be used as criteria to evaluate if a piece of code is understandable. Method. We designed and conducted an empirical study among 216 early career developers with professional experience ranging from one to four years. We asked them to manually inspect and rate the understandability of 12 Java classes that exhibit different levels of Cyclomatic and Cognitive Complexity. Results. Our findings showed that while the old-fashioned McCabe Cyclomatic Complexity and the most recent Cognitive Complexity are modest predictors for code understandability when considering the complexity perceived by early-career developers, they are not for problem severity. Conclusions. Based on our results, early-career developers should not be left alone when performing code-reviewing tasks due to their scarce experience. Moreover, low complexity measures indicate good understandability, but having either CoC or CyC high makes understandability unpredictable. Nevertheless, there is no evidence that CyC or CoC are indicators of early-career perceived severity.Future research efforts will focus on expanding the population to experienced developers to confront whether seniority influences the predictive power of the chosen metrics.
