Code readability is something that I often bring up during code reviews, but I often have trouble explaining why I find a piece of code to be easy or difficult to read.
When you ask programmers how to make code easier to read, many of them will mention things like coding standards, descriptive naming, and decomposition. These are all good things to do, but they aid in making code easier to comprehend. What I’m interested in is at a much lower level: making code easier to read. For me, readability sits somewhere between legibility and comprehension.
At the lowest level is legibility. This is how easily individual characters can be distinguished from each other, and can usually be boiled down to the choice of font, as well as the foreground & background colours.
At the highest level is comprehension, which is the ease in which a block of code can be fully understood. Decomposition, naming conventions and comments are just a few of the many ways to improve comprehension.
In between these two is the level that I’m concerned with: readability. This level is a little harder to define, but I believe it comes down to two main factors: structure and line density. (more…)