An Empirical Study Assessing Source Code Readability in Comprehension

Software developers spend a significant amount of time reading source code. If code is not written with readability in mind, it impacts the time required to maintain it. In order to alleviate the time taken to read and understand code, it is important to consider how readable the code is. The general consensus is that source code should be written to minimize the time it takes for others to read and understand it. In this paper, we conduct a controlled experiment to assess two code readability rules: nesting and looping. We test 32 Java methods in four categories: ones that follow/do not follow the readability rule and that are correct/incorrect. The study was conducted online with 275 participants. The results indicate that minimizing nesting decreases the time a developer spends reading and understanding source code, increases confidence about the developer's understanding of the code, and also suggests that it improves their ability to find bugs. The results also show that avoiding the do-while statement had no significant impact on level of understanding, time spent reading and understanding, confidence in understanding, or ease of finding bugs. It was also found that the better knowledge of English a participant had, the more their readability and comprehension confidence ratings were affected by the minimize nesting rule. We discuss the implications of these findings for code readability and comprehension.

[1]  Anneliese Amschler Andrews,et al.  Program Comprehension During Software Maintenance and Evolution , 1995, Computer.

[2]  R. Flesch A new readability yardstick. , 1948, The Journal of applied psychology.

[3]  Todd Sedano,et al.  Code Readability Testing, an Empirical Study , 2016, 2016 IEEE 29th International Conference on Software Engineering Education and Training (CSEET).

[4]  Chris F. Kemerer,et al.  Cyclomatic Complexity Density and Software Maintenance Productivity , 1991, IEEE Trans. Software Eng..

[5]  Kate Ehrlich,et al.  Empirical Studies of Programming Knowledge , 1984, IEEE Transactions on Software Engineering.

[6]  Dawn J. Lawrie,et al.  The impact of identifier style on effort and comprehension , 2012, Empirical Software Engineering.

[7]  David W. Binkley,et al.  What’s in a Name? A Study of Identifiers , 2006, 14th IEEE International Conference on Program Comprehension (ICPC'06).

[8]  Dror G. Feitelson,et al.  Syntax, predicates, idioms — what really affects code complexity? , 2017, Empirical Software Engineering.

[9]  Venera Arnaoudova,et al.  The Effect of Poor Source Code Lexicon and Readability on Developers' Cognitive Load , 2018, 2018 IEEE/ACM 26th International Conference on Program Comprehension (ICPC).

[10]  Andrew Begel,et al.  Eye Movements in Code Reading: Relaxing the Linear Order , 2015, 2015 IEEE 23rd International Conference on Program Comprehension.

[11]  Yingxu Wang,et al.  Cognitive Complexity of Software and its Measurement , 2006, 2006 5th IEEE International Conference on Cognitive Informatics.

[12]  Barbara Paech,et al.  The Role of Method Chains and Comments in Software Readability and Comprehension—An Experiment , 2016, IEEE Transactions on Software Engineering.

[13]  Errol R. Iselin Conditional Statements, Looping Constructs, and Program Comprehension: An Experimental Study , 1988, Int. J. Man Mach. Stud..

[14]  Michael Beigl,et al.  Descriptive Compound Identifier Names Improve Source Code Comprehension , 2018, 2018 IEEE/ACM 26th International Conference on Program Comprehension (ICPC).

[15]  Margaret-Anne D. Storey,et al.  Theories, Methods and Tools in Program Comprehension: Past, Present and Future , 2005, IWPC.

[16]  Gabriele Bavota,et al.  Automatically assessing code understandability: How far are we? , 2017, 2017 32nd IEEE/ACM International Conference on Automated Software Engineering (ASE).

[17]  Thomas Leich,et al.  Do background colors improve program comprehension in the #ifdef hell? , 2012, Empirical Software Engineering.

[18]  Yingxu Wang,et al.  A new measure of software complexity based on cognitive weights , 2003 .

[19]  Luis Emilio Bruni,et al.  Gaze strategies can reveal the impact of source code features on the cognitive load of novice programmers , 2018 .

[20]  Mario Linares Vásquez,et al.  Improving code readability models with textual features , 2016, 2016 IEEE 24th International Conference on Program Comprehension (ICPC).

[21]  Robert L. Goldstone,et al.  What Makes Code Hard to Understand? , 2013, ArXiv.

[22]  Westley Weimer,et al.  Learning a Metric for Code Readability , 2010, IEEE Transactions on Software Engineering.

[23]  Tuan Nguyen,et al.  "Automatically Assessing Code Understandability" Reanalyzed: Combined Metrics Matter , 2018, 2018 IEEE/ACM 15th International Conference on Mining Software Repositories (MSR).

[24]  Ruven E. Brooks,et al.  Towards a Theory of the Comprehension of Computer Programs , 1983, Int. J. Man Mach. Stud..

[25]  Dror G. Feitelson,et al.  High-MCC Functions in the Linux Kernel , 2012, 2012 20th IEEE International Conference on Program Comprehension (ICPC).

[26]  Tanya Beelders,et al.  Syntax highlighting as an influencing factor when reading and comprehending source code , 2015 .

[27]  Marie Nordström,et al.  Beauty and the Beast: on the readability of object-oriented example programs , 2015, Software Quality Journal.

[28]  Marco Aurélio Gerosa,et al.  Impacts of coding practices on readability , 2018, ICPC.

[29]  S. Jayaprakash,et al.  Properties of Control-Flow Complexity Measures , 1991, IEEE Trans. Software Eng..