[Python-ideas] Objectively Quantifying Readability
dan at tombstonezero.net
Tue May 1 11:02:27 EDT 2018
On Tue, 01 May 2018 22:37:11 +1000, Steven D'Aprano wrote:
> On Tue, May 01, 2018 at 04:50:05AM +0000, Dan Sommers wrote:
>> On Tue, 01 May 2018 10:42:53 +1000, Steven D'Aprano wrote:
>> > - people are not good judges of readability;
>> I happen to be an excellent judge of whether a given block of code is
>> readable to me.
> In the same way that 93% of people say that they are an above-average
> driver, I'm sure that most people think that they are an excellent
> judge of readability. Including myself in *both* of those.
Are you claiming that I'm not an excellent judge of whether a given
block of code is readable to me?
> 2. Anecdotally, we all know that many programmers are just awful.
No argument here! :-)
Readability is only one criterion by which to judge code. Most code on
thedailywtf is bad due to varieties of bugs, inefficiencies,
misunderstandings, or unnecessary complexities, regardless of how
readable it is.
> And presumably most of them think they are writing readable code ...
Why would you presume that? I haved worked with plenty programmers who
didn't consider readability. If it passes the tests, then it's good
code. If I have difficulty reading it, then that's my problem.
Also, when I write code, I put down my text editor to review it myself
before I submit it for formal review. My authoring criteria for good
code is different from my reviewing criteria for good code; the latter
includes more readability than the former.
> ... I have known many people who swear black and blue that they work
> best with their editor configured to show code in a tiny, 8pt font,
> and I've watched them peering closely at the screen struggling to read
> the text and making typo after typo which they failed to notice.
> In other words, people are often not even a great judge of what is
> readable to *themselves*.
On that level, aesthetics definitely count (typographers have known this
for centuries), but in an entirely different way. Is their code better
when their editor shows it at 14.4pt? At 17.3pt?
When we first started with color displays and syntax coloring editors,
it was popular to make a language's keywords really stand out. But the
keywords usually aren't the important part of the code (have you ever
programmed in lisp?), and I find it easier to read algol-like code when
the keywords are lowlighted rather than highlighted. In Python, for
example, the word "import" is far less important than the name of the
module being imported, especially when all the imports are grouped
together near the top of the source file.
More information about the Python-ideas