Does Cyclomatic or Cognitive Complexity Better Represents Code Understandability? An Empirical Investigation on the Developers Perception

03/14/2023
by   Valentina Lenarduzzi, et al.
0

Background. Code understandability is fundamental. Developers need to clearly understand the code they are modifying. A low understandability can increase the amount of coding effort and misinterpretation of code has impact on the entire development process. Ideally, developers should write clear and understandable code with the least possible effort. Objective. The goal of this work is to investigate if 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 junior 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. Cognitive Complexity slightly outperforms the Cyclomatic Complexity to predict the developers' perceived understandability. Conclusion. The identification of a clear and validated measure for Code Complexity is still an open issue. Neither the old fashioned McCabe Cyclomatic Complexity and the most recent Cognitive Complexity are good predictors for code understandability, at least when considering the complexity perceived by junior developers.

READ FULL TEXT
research
09/05/2023

How do Developers Improve Code Readability? An Empirical Study of Pull Requests

Readability models and tools have been proposed to measure the effort to...
research
06/21/2022

To What Extent Cognitive-Driven Development Improves Code Readability?

Cognitive-Driven Development (CDD) is a coding design technique that aim...
research
07/19/2022

Visual Notations in Container Orchestrations: An Empirical Study with Docker Compose

Context: Container orchestration tools supporting infrastructure-as-code...
research
07/24/2020

An Empirical Validation of Cognitive Complexity as a Measure of Source Code Understandability

Background: Developers spend a lot of their time on understanding source...
research
07/02/2019

Understanding Flaky Tests: The Developer's Perspective

Flaky tests are software tests that exhibit a seemingly random outcome (...
research
10/13/2022

Cognitive-Driven Development Helps Software Teams to Keep Code Units Under the Limit!

Software design techniques are undoubtedly crucial in the process of des...
research
03/10/2021

Blindspots in Python and Java APIs Result in Vulnerable Code

Blindspots in APIs can cause software engineers to introduce vulnerabili...

Please sign up or login with your details

Forgot password? Click here to reset