我不用语法高亮编程。
I program without syntax highlighting

原始链接: https://hakon.gylterud.net/opinion/syntax-highlighting.html

## 灰色地带的编程:一个去除语法高亮的理由 作者提倡*不使用*语法高亮进行编程,这种做法源于对编辑器 Acme 的需求,并因个人偏好而保持。虽然承认高亮可以帮助快速发现语法错误(例如括号不匹配),但作者认为它并非必需品。Acme 通过主动选择提供替代的错误检查方式,并且作者发现大多数错误可以通过频繁编译和测试快速发现。 更重要的是,去除颜色可以迫使人们专注于代码的*美观*——整洁的组织、简洁的行以及避免注释掉的代码等杂乱。没有高亮掩盖问题,作者对反模式更加敏感,并保持更干净、更易读的代码。 此外,放弃高亮支持所有语言,避免配置难题,并使编辑器免受不断发展的语言和语法的困扰。作者认为编辑器应该*编辑*,而不是*解析*,将语法检查留给专用工具。最终,他们发现未高亮的 代码,一旦适应,就会变得出奇地易读和逻辑清晰。

## 没有语法高亮的编程:黑客新闻讨论 一篇最近的黑客新闻帖子引发了关于编程时语法高亮是否必要的争论。原作者认为,没有语法高亮可以鼓励更深入地参与代码,使其“结晶成一个美丽的逻辑宇宙”。 然而,许多评论者强烈不同意,其中一些人指出它对可访问性的显著益处——特别是对于患有阅读障碍的人,他们发现颜色编码有助于模式识别并减轻认知负担。其他人强调了它作为快速视觉错误检查器的实用性。 讨论揭示了偏好的光谱。一些开发者,如林纳斯·托瓦兹,有意避免使用它,而另一些人则 heavily 依赖它,尤其是在大型代码库中。 也有人对更语义化的高亮(变量/类型使用独特颜色)和可定制的灰度主题以减少视觉噪音感兴趣。 最终,该帖子强调编程是一种非常私人的实践,而“最佳”方法取决于个人的需求和认知风格。 讨论还涉及了工具的演变,一些人回忆起语法高亮并不常见的时代,现在觉得它是不必要的。
相关文章

原文
How I program without syntax highlighting

For more than a year I have been without syntax highlighting. My editor of choice, acme, simply does not have it and I actually prefer it that way. Some would explain this as an instance of the Stockholm syndrome, or some strange form of hipsterism. However, I think there are some valid advantages to not colouring our texts, and so I will put them forth.

What syntax highlighting is good for

Some people perceive numbers and letters as coloured, and can use this ability to solve some tasks quicker. So initially, giving everyone synesthesia for free using syntax highlighting seems like it should improve our ability to understand code quickly. I do think it does give some speedup in checking wether there are syntax mistakes in the code. The classic example is some sneaky comment errors like this one:

  // Initialise
  for (i=0;i<3;++i) {
    /* Do initialisation here!
    niftyConfig = 1;
    funkyValue = 2;
  }

  // Run forever
  for (;;) {
   /* So, this is where we do stuff! */
  ...
  }

Syntax highlighting is not the only way of telling that your parenthesis, quotes and comments are matched up. In Acme I double click on the outmost marker to check that it has a match. This gives the added benefit that the region is selected if I wish to make edits to it. This is an active action on my part, because usually I know where my parentheisis go and do not need any help.

For most part syntax is not the most challenging part of programming, and I have yet to run into troubles where I could not spot my syntax errors. I usually program in a tight loop of writing, compiling and testing, meaning that any syntax related mistakes are probably in the most recently edited region and are easy to spot.

The beauty of code

The first thing one thinks when going from highlighted to unhighlighted code might be «This code is just a grey mash of symbols». Though, this sensation quickly fades as one gets engaged in the code. This “getting in to the groove”-part of the programming session is remarkably short, and afterwards code is more readable than English.

If the code is neatly organised, the «grey mash» quickly crystalises into a beautiful little universe of logically connected parts; each standing by it self, on its own line or in its own scope, but referencing each other in clear and beautiful ways. However, if the code is disorganised, with commented-out code, overly long lines and all, then the «grey mash» shape-shifts to a minefield in rough terrain, with craters and rocks obscruing the view.

What I am saying is that, coding without the syntax highlighting makes me much more sensitive to code “beauty”. This means that I avoid anti-patterns like having too long lines, or commenting out code. When my syntax highligher would make comments grey, I would frequently have two or three versions of a function in the comments while writing, and have to remind my self go clean the mess up. Now, I much rather copy the old version to a scratch file or buffer before making revisions. This keeps the code beautiful and easy to read.

Supports all languages

Once syntax highlighting is gone, you no longer priviledge the class of languages for which there exists a syntax highlighting. As a programmer you will not spend time looking for a highlighter, and configuring it for your preferences. Since I work a lot in a language called Agda, which is a language with absent support in most editors, this is important to me.

Editors in general suffer from over-configurability. Humans in general, and programmers in particular, like to tinker. Once you start tinkering on the configuration file of your editor, it easily gets in the way of what you actually were supposed to do. Syntax highlighting especially invites to these distractions as it is in your face while programming. If something about it annoys you, you are bound to notice while programming.

Supporting all languages equally future-proves the editor, because who knows which language we will use in ten years? Not to mention that syntax in a given language changes between version: new keywords added, new function syntax, and λ-abstractions added.

This also clears the distinction between the editor and other tools. The editor lets you edit code, it does not parse it and check its syntax. If it does, it is bound to do it wrong when the language changes, and require continual maintainance.

Other people have written about this before

  1. Linus Åkesson
  2. Kyle Isom
联系我们 contact @ memedata.com