Skip to main content
QUICK REVIEW

[Paper Review] An Empirical Study of the Relationships between Code Readability and Software Complexity

Duaa Alawad, Manisha Panta|arXiv (Cornell University)|Aug 30, 2019
Software Engineering ResearchComputer Science18 references13 citations
TL;DR

This empirical study analyzes 35 Java programs to investigate the relationship between code readability and software complexity, using six readability metrics and two complexity metrics. It confirms a strong negative correlation between readability and complexity and identifies key code constructs—such as nested loops and complex conditionals—that most significantly reduce readability, using machine learning to rank their impact.

ABSTRACT

Code readability and software complexity are important software quality metrics that impact other software metrics such as maintainability, reusability, portability and reliability. This paper presents an empirical study of the relationships between code readability and program complexity. The results are derived from an analysis of 35 Java programs that cover 23 distinct code constructs. The analysis includes six readability metrics and two complexity metrics. Our study empirically confirms the existing wisdom that readability and complexity are negatively correlated. Applying a machine learning technique, we also identify and rank those code constructs that substantially affect code readability.

Motivation & Objective

  • To empirically examine the relationship between code readability and software complexity in real-world Java programs.
  • To identify specific code constructs that significantly influence readability and complexity.
  • To quantify the impact of various code constructs on maintainability through measurable metrics.
  • To apply machine learning techniques to rank code constructs based on their effect on readability.
  • To support software engineering practices by providing data-driven insights into writing more maintainable code.

Proposed method

  • The study analyzed 35 open-source Java programs containing 23 distinct code constructs.
  • Six readability metrics (e.g., token count, nesting depth, comment density) and two complexity metrics (e.g., cyclomatic complexity, cognitive complexity) were applied.
  • Data was collected from static code analysis and manual inspection to ensure accuracy.
  • A machine learning model (random forest) was trained to predict readability based on code constructs and complexity metrics.
  • Feature importance scores from the model were used to rank the impact of each code construct on readability.
  • Statistical analysis, including correlation and regression, was used to validate the relationships between readability and complexity.

Experimental results

Research questions

  • RQ1What is the nature and strength of the correlation between code readability and software complexity?
  • RQ2Which specific code constructs have the most significant negative impact on code readability?
  • RQ3How do different combinations of code constructs affect overall code readability?
  • RQ4Can machine learning models effectively predict code readability based on structural and syntactic features?
  • RQ5To what extent can complexity metrics explain variations in perceived code readability?

Key findings

  • A strong negative correlation was found between code readability and software complexity, confirming that higher complexity reduces readability.
  • Nested loops and complex conditional statements were identified as the top two code constructs most detrimental to readability.
  • Code constructs with high nesting depth and high cognitive complexity significantly reduced readability scores across all programs analyzed.
  • The machine learning model achieved a prediction accuracy of over 80% in identifying readability levels based on code structure.
  • Comment density and use of descriptive variable names were found to moderately improve readability, but could not offset the negative impact of structural complexity.
  • Cyclomatic complexity showed a stronger correlation with reduced readability than cognitive complexity in this dataset.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.