5 ms·
One difficulty with these discussions it that there is no standard, objective definition of readability. Without one, it’s hard to debate statements like the ti
by Chris_Newton 14y ago
One difficulty with these discussions it that there is no standard, objective definition of readability. Without one, it’s hard to debate statements like the title of this thread, “Readability can mislead”.
After thinking about this a lot, I settled on a personal definition of “ease of extracting useful information from the code”. This recognises some principles I’ve found to be important when discussing readability and how to improve it. For example, different knowledge will be useful depending on what you’re trying to achieve and what you already know, so code may be more readable for some purposes than others. Similarly, information may be relatively easy to extract for someone with one background or set of tools but harder for someone else to obtain under different circumstances. This means readability is always a balancing act, and something that makes code more readable for one purpose or reader may actually harm the readability in another context.
This explains a lot of subjective preferences based on the reader’s background. For example, in the Good for Whom? article by Daniel Lyons[1] that was cited by the article we’re discussing, there is a question of whether a one-line regular expression does anything to aid readability, and whether a much more verbose Smalltalk-style implementation of the same logic is more readable. I believe the most important thing to recognise in that debate is that the readability of the regex version is dramatically different depending on whether the reader understands regex syntax. If so, it is probably much easier to read than the long form version, but if not, it's just executable line noise. Therefore whether it is helpful to employ a regex for that task depends a lot on who you expect to be reading the code later and what assumptions you are willing to make about their skills and knowledge. A similar dilemma is almost inevitable when choosing almost any significant coding standard.
[1] http://www.storytotell.org/essays/good-for-whom.html http://www.storytotell.org/essays/good-for-whom.html
- cafard 14y agoI think that Marick's comment in the article expresses this well.