A case against syntax highlighting (2007)
linusakesson.net
linusakesson.net
There's also a comparison to highlight syntax in fiction, which is absurd for many reasons. A simple one being that the _goal_ of fiction can often be to obscure meaning for the sake of ambiguity. I'm offended not by the thesis but by the presumptuous nature of the argument.
In many (most?) languages, you can look at where your code stops being colored and see you forgot to close something like a comment or a paren.
I’d never lecture someone on whether they have syntax highlighting like the blog post does. It’s dumb to argue personal preference as if it’s fact.
Wouldn't the compiler find this and the editor mark it as a compilation error?
Syntax highlighting happens in real time. Compiling (at least in my editor), only happens when I say it should.
(I mostly agree with you. My preferred syntax highlighting is for just comments and string literals.)
Alice
was
not a bit hurt,
and
she
jumped up
on to her feet
in a moment:
she
looked up,
but
it was all dark overhead;
before her was another long passage,
and
the White Rabbit
was
still in sight,
hurrying down it.
I mean, just look at it. Would you read a whole book like this? You can't see the semantics for all the obsession with syntax.Case against multi-file projects! Would you read a book if you had to go back to a Makefile or other project artifact to figure out where the next chapter is? Come on, put the whole damn program in one file that reads from top to bottom!
Case against local variables:
but
let P = "another long passage"
it was all dark overhead;
before her was P,
and
the White Rabbit
was
still in sight,
hurrying down P
This is now totally unnatural "STEM speak". Use the good old ambigous anaphoric pronouns, or GTFO!For prose, it's obviously silly, because one point and one goal of prose is to keep the reader in the dark about many wonderful things - or even mislead them to suprise them. So techniques that allow for an easier skimming and back-and-forth (like I did to compare example #2 with example #1) are detrimental there.
A ton of terrible arguments are made here: X is important so Y is not important. ABC is a sacred rule that must be followed without question and doing XYZ does not follow the sacred rule. Wrong thing is done to help dumb people so smart people shouldn't do wrong thing.
The only test is: does it work for you? For a long time, I thought it didn't do much for me, but recently I discovered that highlighting used and unused variables/functions differently helps me find typos, and clean up my code. Comments obviously should be a bit muted. And strings are nice. I don't care much about highlighting keywords, but it doesn't bother me either. I think highlighting the parameters of the function I'm in differently than the rest of my code would help me, but I don't think my IDE does that by default. Maybe it's time to start tweaking my code highlighting.
I really cannot think of going back to plain two-color editors like TP3. Syntax highlighting helps me to spot unterminated strings, mistaken variable names that clash with keywords, plus the general "feeling" of a page of code that I get when I quickly scroll a long source file in search of a specific place.
I do not think that syntax highlighting has spread everywhere just because it looks cool. It is SOOO useful!
A case against syntax highlighting (2007) - https://news.ycombinator.com/item?id=11857006 - June 2016 (77 comments)
A case against syntax highlighting (2007) - https://news.ycombinator.com/item?id=8606065 - Nov 2014 (2 comments)
A case against syntax highlighting - https://news.ycombinator.com/item?id=8262192 - Sept 2014 (3 comments)
A case against syntax highlighting (2007) - https://news.ycombinator.com/item?id=7445455 - March 2014 (1 comment)
A case against syntax highlighting - https://news.ycombinator.com/item?id=3717303 - March 2012 (24 comments)
A case against syntax highlighting - https://news.ycombinator.com/item?id=253114 - July 2008 (1 comment)
With syntax highlighters can be applied same rule as with UI, pleasing interface make it more usable. https://www.nngroup.com/articles/aesthetic-usability-effect/
Color differentials are also a powerful human visual cue. This is why traffic lights are three distinct colors instead of just a top, middle and bottom light.
As to the comparison to prose, well, we have tons of syntax highlighting there too. Capitals at the beginning of sentences. Indentation and spacing between paragraphs, etc.
This is a wild claim, and my own experience shows quite the opposite.
For two years, I have been interacting with source code without syntax highlight.
As a result, I feel I am more focused on the content and less distracted. Particularly, that is very noticeable when reading foreign (i.e. other people's) code.
I actually feel that I read slower, but way more attentive. I actually give my brain the time to process the information, and as a result, I get a lot of overlooked bugs that other reviewers don't.
I still find useful, at times, to make the comments in another color, but I noticed that doing so, my brain ignore the comments and a lot of incorrect comments, that could be corrected, went overlooked several times.
Wishing or not, colours are tax your cognition, and for a visual person as I am, they were way bigger distractions than supports: I don't need colours to tell me "for" is a reserved word.
I also find font ligatures very distracting, but it was way more obvious to me that they contribution was negative compared to syntax highlight.
> Color differentials are also a powerful human visual cue. This is why traffic lights are three distinct colors instead of just a top, middle and bottom light.
Well, semaphores have just three elements, which are never shown simultaneously and the colours are well based on semiotics.
That is not the case for syntax highlight.
Syntax highlight seems closer to Stroop test [1] than semaphores.
> As to the comparison to prose, well, we have tons of syntax highlighting there too. Capitals at the beginning of sentences. Indentation and spacing between paragraphs, etc.
Have you looked to a text written in German? That is… Tiring!
In German, all nouns are capitalised. Reading a prose in German LOokS lIkE this TO mE.
I think syntax highlight is the equivalent capitalisation of nouns in prose.
This is hard to read both because capitalization is a clue that another sentence is starting in English and because uneven multiple capitalization makes it harder to recognize a word. Your brain almost stutters as it pauses to turn the unfamiliar LOokS into looks. Presumably Germans expect the additional capitalization and don't experience this extra processing whereas if you are used to English you are used to deriving different data from more sparsely applied capitalization. While LOokS causes poorer performance for everyone. I think your comparison of highlighting to German capitalization rules is more apt than comparing it to capitalizing random letters.
In keeping with the argument made earlier in the text this ought to improve your understanding of prose because it makes you slow down and really parse it. In reality your brain has a finite amount of processing power and memory and consciously focusing on turning unfamiliar structures into intelligible data and if the data you are taking in is complicated you are taking away resources by being forced to more consciously process it.
You might actually apply this thinking to your experience with syntax highlighting if you aren't used to it you attend to it more so than the data expressed by the code. Your preference and familiarity leads to a different experience than individuals who are used to using it. This doesn't make your preference wrong or right but I question your conclusion that it leads to more attentive reading. I suggest instead that if you discover oft overlooked bugs it is rather because are a more attentive reader rather than being down to reading without syntax highlighting being more effective.
Using different colors for sync vs async calls could be helpful. Or pure vs. impure. Or how many times a function or variable definition is used elsewhere in the code base, exercised in tests, referenced in the documentation, etc. I think I would find this sort of non-local information more useful than syntax highlighting.
There was a blog post linked here a couple weeks ago that used color shading to distinguish levels of nested parentheses, with color shift on mouseover, which was interesting.
The article suggests marking "=" and "==" in different colors, which doesn't seem very useful unless the font shows adjacent = characters with no space between them.
https://github.com/ankurdave/color-identifiers-mode
Inspired by this post
For me syntax highlighting hate is nothing more than luddism.
Not to say that I hate syntax highlighting. Likewise: I carry a lighter camping, but I also know how to make and use a bow drill. I think there's a big difference between learning to live without a technology, and hating that technology. And that's the generous read of this article.
To rebut the author, I've seen an indisputably good use of syntax highlighting: rainbow-colored parentheses in emacs. In most languages, I've got a sixth sense for unmatched parens, braces and brackets -- but that isn't strong enough for lisp.
stupid whoever downvoted you.
I think my favourite was surrounding each mutex lock/unlock operation with lines of %-characters.
%%%%%%%%%%%%%%%%%%%%%%%%%%
mutex_lock(&mutex);
%%%%%%%%%%%%%%%%%%%%%%%%%%
Lovely.Your mutex_lock(&mutex) will be colored exactly the same as any arbitrary foo(&bar), so you’d still want to call it out somehow.
I guess the main benefit I feel I'm getting now is string highlighting and comment dimming. Parens stand out to my brain anyway so I don't think I am benefitting from their being colorized.
"moves focus from content to form", if data drives your code structure, especially easy with functional langs, these two start to become isomorphic.
1 helps with typos , I will notice a weird color and probably underlines if the variable or function is undefined so I can fix the issue before it crashes somewhere in the future
2 also helps me when it highlights unused stuff, shows me that a refactor or a merge happened and it needs a closer look
3 we put JSDoc type documentation and colors will look different if say you used a method on an object that does not have such method or member defined
I create my personalized color schemes that fit me and my disabilities so I don't care if maybe it does not work for someone else or if soem dude tested on some students and observer some small effect or even worse some designer decide how my stuff should look because he read some blog posts from his guru and now he thinks he is a UX master.
I suggest people try a good IDE, tweak things, I always notice bugs in my colleagues code that a good IDE would have prevented them.
When I first started to program, I found syntax highlighting annoying and distracting, but I changed my mind within a year or so. So I have tried both sides and made my choice.
I also think that the usefulness of syntax highlighting depends a lot on what language you are using. For example, I found it very helpful when working with Perl, but nearly pointless when writing SQL. Like I said, one size does not fit all.
Also, avoid RGBi colors. They are horrible, period.
Unfortunately, most blog posts and documentation on web sites spam syntax highlighting in my face. For those cases I copy the code in my editor to read it which also has the benefit of allowing me to see it with proportional fonts. I use proportional fonts for my programming.
One hypothesis that I came out with might be that advertising competes for my attention using lots of colors, and I have become very experienced in tuning out any kind of advertising. I don't consciously associate colored text with advertising, but for whatever reason the mechanism seems to be active in my brain.
Sometimes color highlighting actually serves as an objectively beneficial function, for example colored grep output or colored diff output. Even in those cases I still have to turn colors off, otherwise I simply skip past the important bits of the text that are highlighted.
This error helps make the author’s point:
> Maybe it was introduced in order to flatten the learning curve.
The steeper the curve, the easier to learn, so I suppose by flattening it you are deliberately making learning the piano more difficult.
I have occasionally heard people get it backwards but I assume they are just copying the term without bothering to learn what it means.
> The common expression "a steep learning curve" is a misnomer suggesting that an activity is difficult to learn and that expending much effort does not increase proficiency by much, although a learning curve with a steep start actually represents rapid progress. In fact, the gradient of the curve has nothing to do with the overall difficulty of an activity, but expresses the expected rate of change of learning speed over time. An activity that it is easy to learn the basics of, but difficulty to gain proficiency in, may be described as having "a steep learning curve".
https://en.m.wikipedia.org/wiki/Learning_curve
So the term "steep learning curve" is well-established and my interpretation was correct, but my analogy was wrong. The OP seems to be using it correctly according to the above quotation. "Steep" is a misnomer, but that doesn't make using the term wrong.
Like people who don’t realize that the “ugly american” was the hero of the novel (being unlike the pampered, out of touch elites).
Language is weird but this kind of thing makes things people say quite hard to understand.
It's an unfortunate comment since I struggle with word salad most days. Being able to skim and find certain blocks or aspects of a source file is preferable if I can't remember the name of something right away.
I'm not convinced, but this is an interesting take.
The selected examples are unfair as they use a badly contrasted foreground color against a white background which break all the WCAG Guidelines for contrast. IDEs should use colors with an accessible contrast ratio.
#00dd00 (green) -> #ffffff: 1.85:1 - fail on all results
#00dddd (cyan) -> #ffffff: 1.70:1 - fail on all results
I feel another exception would be the differentiation of static, member and local variables as an additional IDE-based hint, on top of naming conventions.
Look at the authors own example, if you want to change the number of iterations in the loop or edit a type, you can do that practically instantly. Does this come at the cost of readability? Perhaps. This is also probably subjective and for the author the cost is apparently too great.
I don't know what it is about programming that churns out these takes about not using effective tools and making things harder on yourself. There's this odd strain of ascetic masochism that breaks out from time to time that I can't say I've observed much in other subcultures.
* based on Acme http://acme.cat-v.org/
https://github.com/DigitalMars/med/commit/adcc084e2142723695...
A point of counter-evidence. Developers seek out syntax highlighting. Perhaps they've all been duped by the hype. Orrrrrrr they actually find it helpful.
Without more evidence, I'm going with #2.
In 2007, I might have agreed.
In 2021, I've added syntax highlighting to my own editor (and things feel harder without it).
The main reason why I use syntax highlighting is because I'm use to it and it looks cool.
Syntax highlighting is about understanding structure.
I could blur out my editor to the point where I could not make out individual letters and still understand the code structure.
When reading prose you don’t care about structure, especially not in English (in latin languages structure is way more important).
It’s important to have a good highlighter though. STM32cube IDE has a very bad highlighter that gets confused sometimes.
I’ve seen people chasing simple bugs for far too long just because the highlighter was broken.
We use all sorts of typographical conventions to draw attention to the things we want emphasis drawn to or to encode some notion. In many novels, in English at least, a character's thoughts are italicized rather than quoted. The noir detective might be found at his desk thinking, I knew I'd seen her before, but no name came to mind. In textbooks you have a mix of bold and italics used to identify specific kind of content. Bold for new keywords students of the book should keep in mind, usually adjacent to a definition. Italics might indicate a name assigned to something: Using the pumping lemma we can...
Perhaps in our code editors we've overdone highlighting, or coloring could be a poor (certainly for some colorblind readers) method of highlighting, but syntax highlighting itself can make a great deal of sense.
It's worth considering that in the examples from prose, we usually don't draw attention to syntax, but to semantics. What does the thing with different typography mean, why is it given that special formatting or why is it surrounded by special brackets, dashes, or quotes. We don't highlight (as in the example in the article) nouns one way, verbs another, adjectives a third, and adverbs a fourth. Or verbs different ways depending on the tense or number. We highlight individual words in some manner to bring attention to them, or groups of words to indicate their logical separation in some sense from their surroundings.
I think the main benefit to highlighting code is it’s one less task my brain has to do, freeing it up to think about the structure of the code in writing and the bigger picture.
Searching your code for that our of place ‘ is no benefit to anyone.
Sorry it was a standard feature in some IDE's like forever. Nothing is modern about it except the fact that the amount of what being recognized and made visually different did increase thanks in good part to language servers.
As for giving it up - well for what I care they could still use punch card, their choice. For me - I would not give it up.