# Introduction
Howreadable is an online experiment investigating how programming constructs affect code readability. The aim is to find descriptive readability rules that are based on empirical observation of developer behaviour.
The experiment ran for one month from 11/10 to 09/11/2019 with 545 participating developers. Participants were shown a series of code snippets and then asked to answer a question to test their comprehension. If they answered correctly, we recorded the amount of time they spent reading the code snippet.
# Findings
In total we tested 11 coding constructs, finding statistically significant results for six of them:
- Operator precedence: In expressions that are dependent on operator precedence, adding brackets increases both reading speed and accuracy.
- Chaining methods: Chained methods are faster to read, but adding intermediate variables leads to greater accuracy.
- Order of if statements: If statements are faster to read when the positive case is presented first.
- Extracting functions: There is a reading speed overhead when extracting functions.
- Pure functions: There is a reading speed overhead when writing pure functions.
- Boolean algebra: Expanded boolean expressions are faster to read than simplified ones.
# Motivation
Code readability is a key factor in the productivity of software development, but there is surprisingly little literature on the subject that is based on evidence. A developer who is seeking to improve the readability of their code will find advice based almost exclusively on personal opinion. There has been some academic research on the subject, but even that is based on developers subjectively assessing code. What is lacking is an objective metric for readability based on empirical observation.
The inspiration for this project came from the world of linguistics, where the traditional view of grammar as a set of prescriptive rules was superseded by a search for descriptive rules based on observation.