TL;DR
This paper explores how the "difficulty" of a programming language's vocabulary and how "natural" (repetitive) code is affect how easily developers understand it. They propose new metrics for these concepts and investigate their correlation with existing readability and understandability measures, aiming to improve automated code comprehension tools.
What Problem Does This Paper Address?
Understanding source code is a huge part of a developer's job, consuming a significant portion of their time. While there's a lot of research on automatically assessing code readability and understandability, current methods often fall short. They tend to focus on local code characteristics (like complexity metrics) and haven't consistently shown strong correlations with actual human understanding. This paper argues that we're missing a crucial perspective: how language acquisition works. Just like in natural language, where difficult vocabulary and unfamiliar phrasing make comprehension harder, the authors hypothesize that complex or unnatural code elements in programming languages also hinder understanding. They aim to bridge this gap by investigating "vocabulary difficulty" and "code naturalness" as key factors.
Methods
The core of this research lies in defining and measuring two novel concepts:
- Vocabulary Difficulty: This is assessed by creating a manually curated list of Java elements (keywords, literals, operators, JDK method calls) and assigning them difficulty levels based on their appearance in introductory to advanced Java textbooks and Oracle's certification paths. Easier elements appear earlier, corresponding to a natural language learning progression. Metrics derived from this include the count and ratio of elements at each difficulty level, a weighted sum of difficulty levels, and the highest difficulty level present.
- Code Naturalness: This is measured using cross-entropy, a concept borrowed from natural language processing. The idea is that code that is more repetitive and predictable (i.e., uses common patterns and elements frequently seen in other software projects) is more "natural" and thus easier to comprehend. They plan to build n-gram language models on large Java codebases to estimate this.
The researchers will then analyze the correlation between these new metrics and existing readability/understandability scores from human evaluations. Furthermore, they propose to integrate these new features into existing prediction models to see if they can improve performance.
Datasets
The study leverages existing datasets that include human evaluations of code readability and understandability. These are primarily focused on Java:
- For Readability:
- Dorn [6]: 120 Java snippets with 1-5 Likert scale readability ratings.
- Börstler and Paech [16]: 30 snippets (modified versions of original snippets) with 1-5 Likert scale readability ratings.
- Scalabrino et al. [13]: 200 Java methods with readability ratings from nine evaluators.
- For Understandability:
- Scalabrino et al. [3]: 50 Java/Android methods with comprehension tasks (understanding the method and answering verification questions), measuring time spent and correctness.
- Börstler and Paech [16]: 30 snippets with cloze tests (filling in blanks) to measure comprehension, recording time and accuracy.
- Peitek et al. [17]: 23 code snippets with tasks to determine output, measuring time and correctness.
The paper notes that while the Dorn dataset link is broken, a copy is available in the online appendix of Scalabrino et al. [13].
Key Insights and Ideas
- Analogy to Natural Language Acquisition: The core idea that programming language comprehension might mirror natural language acquisition is a significant shift from purely structural code analysis. This opens up new avenues for understanding why some code is harder to grasp than others.
- Beyond Local Features: The paper explicitly addresses the limitation of prior work focusing only on local code features. By introducing "vocabulary difficulty" and "code naturalness," it brings in a more global, contextual perspective.
- Quantifying "Naturalness": Using cross-entropy to measure code naturalness is an innovative application of NLP techniques to software engineering, aiming to capture the predictability and repetitiveness of code.
- Differentiating Readability and Understandability: The paper acknowledges and aims to further explore the distinction between code being easy to read (legible) and easy to understand (comprehensible), a nuance often blurred in prior research.
Key Results
This paper is a registered report, meaning it outlines the planned study and hypotheses before conducting the experiments. Therefore, there are no empirical results to report yet. The paper focuses on the research questions and hypotheses:
- RQ1 & RQ2: Investigating the correlation between vocabulary difficulty and code naturalness with readability and understandability.
- Hypotheses suggest that more difficult vocabulary and less natural code will lead to lower readability and understandability.
- RQ3 & RQ4: Examining whether these new features can improve the performance of existing readability and understandability prediction models.
- Hypotheses propose that integrating vocabulary difficulty and code naturalness will enhance prediction accuracy.
Limitations and Future Work
- Threats to Validity: The authors acknowledge several threats:
- Construct Validity: Annotator bias due to personal experiences is a concern, though mitigated by using multiple datasets from different research groups.
- Internal Validity: Confounding factors like code length and the presence of comments could influence results. The authors plan to address this through controlled analyses.
- External Validity: The study focuses on Java, so generalizability to other languages is uncertain, though the concepts are believed to be applicable. The applicability to closed-source commercial software versus open-source projects is also a question.
- Future Work: The immediate future work involves executing the planned study, analyzing the data, and building prediction models. The long-term goal is to develop more accurate automated tools for assessing code comprehension. The paper also mentions releasing their data and scripts for replication.
Summary updated