TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Syntax highlighting is a waste of an information channel

196 pointsby adenadelalmost 5 years ago

30 comments

megameteralmost 5 years ago
This kind of nibbles at the edges of the longstanding question: Whether source code is best represented as a linear document.<p>Because historically, that was true for the obvious reasons of pragmatism; you could put it on a punchcard, print it to paper, save it to a file all using the same character encoding and rendering methods, and when we went to interactive editing that didn&#x27;t change: half of the joy of plaintext is that you can select, copy, paste, search and modify in mostly standard ways across many tools.<p>Syntax highlighting is incrementally in line with this paradigm since there&#x27;s only one syntax for the language(syntax extension and mixed-language documents aside) and it too follows a linear order, although it also recognizes that an AST exists. But as you get into stuff like code folding, Intellisense and other IDE-like features, deviations emerge. More of the selections deal with symbolic meanings(declarations, types) and not really the tokens or the characters they consist of, and only incidentally the delimiters of the AST.<p>But - when we try to fully re-envision it and express these other concepts directly we tend to end up with something that is unfamiliar, a bit clunky and alienating(most graphical languages). So the accepted developments always seem to come in these little ideas that are mostly-optional add-ons.<p>Chuck Moore did use semantic color as a language feature in ColorForth, but his specific goals lean towards a holistic bootstrapping minimalism, so I haven&#x27;t seen it taken up elsewhere.
评论 #23904658 未加载
评论 #23907095 未加载
评论 #23905274 未加载
评论 #23905809 未加载
评论 #23905759 未加载
评论 #23905941 未加载
评论 #23906724 未加载
duskwuffalmost 5 years ago
I don&#x27;t buy it.<p>1. I personally find syntax highlighting incredibly helpful as a way of setting off syntactic elements, and incidentally as a way of calling attention to typos (like a missing quote or misspelled keyword). The author seems to dismiss this without any analysis.<p>2. Using color for syntax highlighting doesn&#x27;t mean you can&#x27;t <i>also</i> use color to highlight other useful things (like search results or errors), as the author suggests. Many editors which support syntax highlighting do exactly this!<p>3. The author&#x27;s examples aren&#x27;t particularly compelling. For example, using colors to denote levels of nesting will make code flash between colors as you edit it. Highlighting variables by type feels like a form of syntax highlighting, not something new, and most of the examples of highlighting code which meets specific conditions (variables which are assigned to multiple times, long functions, functions without documentation, etc) all feel like they could be summarized as &quot;linter warnings&#x2F;failures&quot;.
评论 #23906292 未加载
评论 #23905266 未加载
评论 #23905794 未加载
gnicholasalmost 5 years ago
Some people are reacting to the (clickbait-y) title, which is a more extreme statement than what the author ends up advocating. The ultimate argument is that it&#x27;s ok to syntax highlight sometimes, but sometimes it might be helpful to use color in other ways.<p>Personally, I find syntax highlighting to be very useful, but I also agree that using color in other ways can be more useful at times. As it happens, syntax highlighting was one of the inspirations for the color gradient text pattern I developed to make reading on screen easier. [1] The existence of syntax highlighting helped me to think about color in text as an information channel that can be used to make certain tasks more efficient, so I&#x27;m very grateful for that!<p>1: <a href="https:&#x2F;&#x2F;chrome.google.com&#x2F;webstore&#x2F;detail&#x2F;beeline-reader&#x2F;ifjafammaookpiajfbedmacfldaiamgg?hl=en" rel="nofollow">https:&#x2F;&#x2F;chrome.google.com&#x2F;webstore&#x2F;detail&#x2F;beeline-reader&#x2F;ifj...</a>
mmmkkaaayyalmost 5 years ago
If you haven&#x27;t before, I&#x27;d recommending giving Intellij&#x27;s semantic highlight a look: <a href="https:&#x2F;&#x2F;blog.jetbrains.com&#x2F;pycharm&#x2F;2017&#x2F;01&#x2F;make-sense-of-your-variables-at-a-glance-with-semantic-highlighting&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.jetbrains.com&#x2F;pycharm&#x2F;2017&#x2F;01&#x2F;make-sense-of-you...</a><p>Every variable name is assigned its own color, so you can track the data dependencies in your function using color. Similar to what the author suggests as &quot;Type Highlighting&quot;<p>Some might consider it distracting&#x2F;overstimulating, but I find it both useful and it makes the code look a bit more &#x27;artistic&#x27;.
评论 #23914021 未加载
评论 #23906929 未加载
matharminalmost 5 years ago
VSCode semantic highlighting is mentioned by the author, and it does support these type of use cases. It works by first doing normal syntax highlighting, then asynchronously getting the semantic info for semantic highlighting, since it&#x27;s a much slower process.<p>The current language-specific implementations do use it to just augment the syntax highlighting, since that is what is what most people would expect. But out of the box it already supports some use cases the author mentioned, such as different highlighting for imports or constants. The full AST and type info can be used for this (depending on the language server), so pretty-much anything is possible.<p>What I personally find very useful (and had to hack experimental support for) is highlighting of TypeScript async&#x2F;Promise values and functions. This is something that a language server can identify easier than humans, and can make a big difference in coding.
adrianmonkalmost 5 years ago
Too much color ends up overwhelming. I can find the red circle super quick because it&#x27;s the only red thing in a sea of black and white.<p>But I like the idea of going beyond syntax. Maybe a way to get the best of both worlds would be to have keyboard shortcuts that toggle cycle through different views. Press this shortcut to color-code types, press this other one to color-code error handling, etc.<p>Also, maybe other visual depictions might be useful. Maybe parentheses could start off very tall and get slightly shorter as you go a layer inward. Or add a 3D&#x2F;depth shading effect so that code each level of parens literally looks like a level. Or whatever else you can think of, the point being that it doesn&#x27;t have to be color.
评论 #23907907 未加载
heapslipalmost 5 years ago
I think too much syntax color is an easy way to shoot yourself in the foot as a developer. When everything is highlighted, and everything is important, nothing is important.<p>We need to choose what is important, I like to highlight language keywords as grey, function names as blue and numeric values &#x2F; strings as purple &#x2F; green. Everything else is white, and it works great.<p>tree-sitter[0] should end regex-based syntax highlighting, check this out for nvim: <a href="https:&#x2F;&#x2F;github.com&#x2F;nvim-treesitter&#x2F;nvim-treesitter" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nvim-treesitter&#x2F;nvim-treesitter</a><p>I really want to see tree-sitter used to power an awesome linter, that works across languages.
评论 #23905453 未加载
wafalmost 5 years ago
Visual Studio does semantic highlighting for at least C# (they call it enhanced highlighting). Static classes, parameters, internal structure of regex strings, etc. Basically anything returned by the Roslyn Classification API.<p>I personally like it, but I think other people feel that syntax highlighting plus semantic highlighting leads to rainbow soup.
评论 #23903805 未加载
Animatsalmost 5 years ago
Syntax highlighting shows something that&#x27;s already visible. What could be highlighted that <i>isn&#x27;t</i> already visible?<p>Undefined variables? Those really should get a squiggly underline, as with spell checkers. Some IDE probably does that already.<p>Anything more subtle?<p>A key point in language design and program tooling is detecting that thing A, which needs to be consistent with thing B far away in some other module, isn&#x27;t. Most hard to find defects involve some distant relationship. What could be done with color or other automatic annotation to help?
评论 #23908694 未加载
评论 #23906031 未加载
评论 #23905251 未加载
jarofgreenalmost 5 years ago
A really good post, but problem 2 is the biggie here:<p>&gt; What if something needs to be colored two things for two different reasons?<p>As another commenter points out, JetBrains already do a lot of the ideas this person has raised - but they do it in response to actions. Eg. Put the cursor next to one bracket, the matching bracket is highlighted.<p>I think the key to breaking this open is an editor that does different highlights at different times in response to user actions; the key will be getting the right user actions so this is seamless and easy to use.
Symbiotealmost 5 years ago
I don&#x27;t think this is suggested: highlight all uses of a field in a class, or a variable in a method.<p>IntelliJ does this for the field&#x2F;variable under the cursor, with a background colour and a margin colour. I&#x27;d like to see what it would be like with all variables in their individual colours.
评论 #23904495 未加载
smt88almost 5 years ago
JetBrains IDEs do almost all of these already, mostly without plugins. Other IDEs probably do, too.
mdfalmost 5 years ago
Good points in this post, although I&#x27;d add the word &quot;Only&quot; in front of the headline.<p>IMO, syntax highlighting definitely has its uses, but why limit ourselves to only using colors for that? I&#x27;d like to see a future, where depending on whether I&#x27;m, for example:<p>- sketching the structure for a completely new program,<p>- implementing a new feature to an existing program,<p>- refactoring an existing program,<p>- debugging a problem in my program,<p>- writing tests, or<p>- trying to find something for reference<p>I&#x27;d be able to seamlessly switch between different highlighting schemes. I don&#x27;t (yet) know what I&#x27;d prefer for each of these different modes of software development. The author of TFA lists some ideas for some different ways of doing semantic highlighting. Maybe over the years I&#x27;d grow to like some of them for some of these tasks.
JohnBootyalmost 5 years ago
I&#x27;d like to see a <i>truly</i> flexible code display system that treats things as a matrix.<p>As the author describes, you have a number of possible concepts we might like to visually denote:<p>- Language constructs (ie, traditional syntax highlighting) - Parentheses&#x2F;bracket pairs - Context highlighting - etc etc etc.<p>The author considers a single &quot;information channel&quot;, text color.<p>There are other possible, largely orthogonal, information channels.<p>- Text background color - Font weight (light&#x2F;bold&#x2F;regular) - Font face - Font italic &#x2F; upright - Font underlines (single, double, dashed, bold, squiggle, etc) - Font underline color? - Perhaps font effects (shadow, blur, etc) - The editor gutter (Sublime and others expose this) - Hover state (ie, tooltips)<p>I&#x27;d like a text display system that lets me mix and match inputs and outputs, matrix style. Perhaps I&#x27;d like to use font weights to denote one concept, and underlines for another.<p>Perhaps I&#x27;d like to use standard text-color choice for language constructs ala traditional syntax highlighting, and text background color for &quot;context&quot; or &quot;semantic&quot; highlighting (where each variable gets a unique color within its scope)<p>It would most certainly be able to create some real visual nightmares with this level of control, but applied judiciously, it could be very valuable.
heavenlybluealmost 5 years ago
Written by an author who had never seen IntelliJ IDEAs highlighting framework.<p>Yes, it does syntax highlighting, but it also manages to mix it up with local variables, etc.
the_otheralmost 5 years ago
I&#x27;ve got a muddled response to this.<p>On one hand, it sounds really helpful and exciting to have tools assist us with these problems e.g. I&#x27;ve read the &quot;show nesting&quot; idea before and wondered why we don&#x27;t have it yet. Yet on the other hand, I think the post misses the mark in some ways.<p>Most IDEs and editors working with most typed languages already do more than colouring in types: they typically hint ahead of entering characters what type of thing should go in each place where a typed thing can go. I think this is more useful than colour, and we already have it.<p>Taking this further, if our editor has toggles for the categories listed, and thus if it has ASTs (or equivalent things) to work over for semantics, then it probably could do even more than highlighting. Some editors already help you refactor: renaming identifiers across a project, pulling functions out etc. It&#x27;s not just colouring, it&#x27;s active involvement with the code, its&#x27; types and behaviours.<p>Further, the author deployed an overly simplistic view of colour and our visual perception. In my case, the &quot;red&quot; circle wasn&#x27;t much easier to find because it was red, but because it was filled in. If it had the same colour as the rounded squares, and was filled in, I would have found it just as fast. The <i>real trick</i> in the grid examples is that some tool (in this case the author) had identified the significant information and done <i>something</i> about it, before the reader even got to apprehend the situation. Tooling which does this would absolutely be more powerful than tooling which doesn&#x27;t. We already have tools which do some of these things. The drive shouldn&#x27;t be &quot;we need more colour?&quot; the drive should be &quot;what features are most helpful to coders?&quot;
Konohamarualmost 5 years ago
The author raised an interesting point with respect to syntax highlighting for types. I find the convention that literals be typed (ints, strings, etc...) to be inappropriate. That is very low-level and these should always be inferred.<p>Where typing should exist is at the level the author suggests, such as<p>* Iterators * List-like structures * Functions that return option types<p>and other more abstract structures.
minikomialmost 5 years ago
I&#x27;ve experimented with using various &quot;semantic depth&quot; color schemes when writing clojure.<p>Depending on the code it can be useful.<p>Some I tried:<p>- <a href="https:&#x2F;&#x2F;github.com&#x2F;istib&#x2F;rainbow-blocks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;istib&#x2F;rainbow-blocks</a> - rainbow blocks, the &quot;OG&quot; - <a href="https:&#x2F;&#x2F;github.com&#x2F;seanirby&#x2F;rainbow-blocks-bg" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;seanirby&#x2F;rainbow-blocks-bg</a> - rainbow blocks but background style - <a href="https:&#x2F;&#x2F;github.com&#x2F;alphapapa&#x2F;prism.el" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;alphapapa&#x2F;prism.el</a> - Prism, a slightly more &quot;friendly&quot; rainbow blocks implementation
perl4everalmost 5 years ago
I find the unhighlighted circle to be about as quick to identify as the red one.<p>Also, I work for someone who is color blind. This whole attitude of &quot;we must do something really important with color because it&#x27;s so powerful&quot; goes against the idea that it has to be optional.
评论 #23905320 未加载
评论 #23906209 未加载
评论 #23905947 未加载
评论 #23905925 未加载
sradmanalmost 5 years ago
The use cases demonstrated are compelling but there seems to be an underlying assumption that current syntax highlighting techniques are broken. After reading the article I&#x27;d argue that there is a case to be made for enhanced but temporary syntax highlighting modes where most highlighting classes are muted except the focus of your attention, such as imported package variables.<p>Consistency is important, both for style and syntax highlighting. It is hard to anticipate what a developer is mentally focused on as they scan code.
falcolasalmost 5 years ago
What’s amusing to me is how few suggestions around highlighting ignores the vast amounts of whitespace that surrounds every character. Borders (partial and full), underlines, strikethrough, background colors, font faces... so many options, yet are we’re constantly limiting ourselves to the color of a letter and the occasional red squiggle.<p>The one valid excuse I can think of is “my editor doesn’t support it”, to which I say BS. VIM, in a terminal, can do most of those.
dragonwriteralmost 5 years ago
&gt; Why aren’t things this way?<p>They...are. With proper extensions, for example, VSCode does many of those things, and can switch which of the supported things it is doing, on top of also doing syntax highlighting, and some of the changes are automatic and context-driven.<p>And while VSCode is my current daily driver, that&#x27;s been true of code editors for quite some time.
raxxorraxalmost 5 years ago
This is somewhat true, although I think keywords should still be highlighted. I once wrote a plugin that highlighted all labels in different colors. Even with a good palette it was really bad... The scope or block highlights could be useful. Difficult for some languages probably, but I would give it a shot.
jnxxalmost 5 years ago
He somehow missed rainbow identifiers, which is quite useful to represent the data flow in a function:<p><a href="https:&#x2F;&#x2F;www.emacswiki.org&#x2F;emacs&#x2F;ColorIdentifiersMode" rel="nofollow">https:&#x2F;&#x2F;www.emacswiki.org&#x2F;emacs&#x2F;ColorIdentifiersMode</a>
mmgutzalmost 5 years ago
Egads ... that rainbow parentheses suggestion is horrific to my eyes. Most editors already do a good job of showing matched braces without shouting.<p>The problems he mentions are not tied to syntax. We need better CONTEXT aware highlighting is the gist of the article.
pragmatickalmost 5 years ago
I use <a href="https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;10080-rainbow-brackets" rel="nofollow">https:&#x2F;&#x2F;plugins.jetbrains.com&#x2F;plugin&#x2F;10080-rainbow-brackets</a> for IntelliJ to color matching brackets.
评论 #23905222 未加载
Already__Takenalmost 5 years ago
I don&#x27;t know how to make it but I always wanted a vscode extension to text background colour what scope you were in for teaching. The rainbow vomit some beautifully indented student python would be...
erikbyealmost 5 years ago
This is awful, a mess. I prefer little to no syntax highlighting, just a grayscale theme with some bold and italics. Actual code clarity (naming, etc.) and structure (indentation, whitespace, etc.) is what is important.<p>Recently there was an article here about what makes a good photograph, one element was few colors, bringing focus to what matters. That is what code should look like, like a good photograph. Not like a rainbow exploded.
评论 #23905575 未加载
reportgunneralmost 5 years ago
I don&#x27;t get it. Author is a programmer, why doesn&#x27;t he just develop this? I don&#x27;t need this and I don&#x27;t want it bloating my text editor.
gsliepenalmost 5 years ago
Syntax highlighting is very useful, if not then it wouldn&#x27;t be so commonplace. The other highlighting methods are also useful. But there is not one objective best highlighting method, it actually changes from moment to moment depending on what you are doing. And many editors in fact already change how they highlight things based on the context! For example, when I search for something, my editor highlights all matches. If my cursor is on an opening bracket, it will start highlighting the matching closing bracket.<p>Some of the highlighting methods shown in the article also seem a bit useless to me. Assigning colors to indentation levels? Surely the indentation itself is a huge visual clue already that doesn&#x27;t need colors to be wasted. The rainbow parentheses example also shows that there are limits to how many obiously distinct colors you can actually have on screen at the same time, and the colors don&#x27;t uniquely show nesting levels.
评论 #23905532 未加载