Context
Code readability is one of the most important quality attributes for software source code. To investigate which features affect code readability, most existing studies rely on correlation‐based methods. However, spurious correlations (a mathematical relationship wherein two variables appear to be causal but are not) involved in correlation‐based methods may affect research conclusions.
Objective
In order to remove spurious correlations and obtain conclusions from the perspective of causation as to what makes a readable code, we propose a causal theory‐based approach to analyze the relationship between code features and code readability scores.
Method
First, we adopt the PC algorithm and additive noise models to construct the causal graph on the basis of the selected code features. Then, we use the linear regression algorithm based on the back‐door criterion to obtain the causal effect of different features on code readability.
Result
We conduct a set of experiments on readability data labeled by human annotators. The experimental results show that the average number of comments positively impacts code readability, with each additional unit increasing the code readability score by 0.799 points. Whereas the average number of assignments, identifiers, and periods have a negative impact, with each additional unit decreasing the code readability score by 0.528, 0.281, and 0.170 points respectively.
Conclusion
We believe that our findings will provide developers with a better understanding of the patterns behind code readability, and guide developers to optimize their code as the ultimate goal.