Syntax highlighting is juvenile - jaredgorski.org

Syntax highlighting is juvenile

It's a quote by Rob Pike.

It's a bombastic statement, but it's Rob Pike. I'm sure he's onto something. So, I took the bait. Three days ago, I fired up Vim to start my morning tasks and immediately typed :syntax off.

Here's what I learned.

Syntax highlighting introduces visual bias

Coloring words differently introduces a new form of bias into what was an otherwise relatively unbiased system. When I say "bias" I'm referring to any of the ways a reader might discriminate between words and potentially prefer some to others when comprehending them. Words can be differentiated by their length, by their spelling (which letters they include), and potentially even by their attractiveness (visually or even phonically if the reader reads aloud in their head).

Some words are more important than others. For example, if we pulled a page out of the Chicago Tribune and removed all of the indefinite articles ("a", "an", "the"), a reader would likely still understand what's written. If I removed all of the nouns, it'd be a different story (literally).

If we applied syntax highlighting to that page from the Tribune, we'd likely color the articles in a less-noticeable color (off-white, assuming a black background) and the nouns in a more-noticeable color (blue or red, assuming Monokai). Imagine doing this. It'd be jarring to read. Articles help to clarify the nouns and "smooth out" the prose, and the differences in color would introduce visual bias which might cause readers to skip the articles in favor of the nouns.

In fact, for the sake of illustration, here's a short excerpt from Moby Dick with the articles in gray, verbs/adjectives/conjunctions in cadetblue, and the nouns in bold cornflowerblue:

Among the Dutch whalemen these scraps are called "fritters"; which, indeed, they greatly resemble, being brown and crisp, and smelling something like old Amsterdam housewives' dough-nuts or oly-cooks, when fresh. They have such an eatable look that the most self-denying stranger can hardly keep his hands off.

When I read that paragraph, my eyes skip immediately over the articles and verbs/adjectives in favor of the "more important" words. Even when I try to read more intentionally, I feel like my eyes "stumble" over the more prominent cornflowerblue nouns. As a result, I feel like I have to work harder to actually understand what the text is telling me. Granted, I instantly know it involves whalemen and donuts, but comprehending the details of what kinds of whalemen and donuts are involved requires moving my eyes backwards from the "key" words to reread the "joining" words and ascertain their positional and contextual meanings.

This applies to code, because code is like prose1.

Code is like prose

Code, like prose, is composed of syntax and semantics. Flow and meaning. Each "word" in code needs a certain degree of context to determine what it means and does, and the flow of those words (and their punctuation) composes the syntax of whatever programming language they're written in.

The grammatical structure of a sentence plays a role in determining the meaning of that sentence. In other words, syntax impacts semantics. Check out this article which illustrates what it takes to create syntactically and semantically correct sentences. Take some time to consider how these concepts apply to code, as well as to prose.

Though syntax highlighting doesn't actually change the syntactical structure of the "code sentences" we write, it does change how we weigh certain pieces of that structure relative to others and, therefore, how we may construct the sentences in our minds as we read them. This potentially impacts how the code is treated by our interpretation mechanisms and, therefore, how we might refactor that code (or even write it in the first place). To say that syntax highlighting necessarily detracts from code quality is tenuous and hasty in my estimation. But, if code is like prose, the syntactic structure perceived by the reader likely has some impact on the way that code is interpreted when it's read. And since, as Uncle Bob Martin says, "the ratio of time spent reading versus writing is well over 10 to 1" and "we are constantly reading old code as part of the effort to write new code", the way we read and comprehend our code will likely impact the way we write and rewrite that code.

Takeaway

I think syntax highlighting has deprived me (at times) of becoming familiar with the syntactical (and, therefore, logical) flow of the code I'm writing. This may not be true for anyone else; I'm perfectly content being the only programmer in the world who may have been, to some extent, "writing by colors". Either way, I feel that removing syntax highlighting has freed me to isolate and analyze the logical topography of my code, regardless of the biases syntax highlighters might place on certain keywords. At the very least, I know that I'm not training my mind to depend on color patterns in order to comprehend and synthesize code.

Other thoughts and links

Shameless plug

Needless to say, I made SpaceCamp monochrome and called it "fogbell.vim". The comments are dimmed, but the syntax is otherwise undecorated.