Highlighting My Code Based on How Much I Care

(hank.bond)

62 points | by hankbond 2 days ago ago

29 comments

  • sph 2 hours ago

    I am convinced everybody gets syntax highlighting wrong and this article backs me up.

    My pet peeves:

    - I have no idea how people are supposed to be productive with non-semantic rainbow vomit themes that are so popular in modern editors. I'm too ADHD to want to be overly stimulated by useless information.

    - I routinely hate encountering Zig code on Github, where the theme they use turns everything brown. Oh it's because it's a struct member. Dude, everything is a struct member in Zig, it's silly to allocate a vibrant colour for what amounts to 90% of the source code. Random example off my browser history: https://github.com/foxnne/aftersun/blob/main/src/time/enviro...

    - Yesterday I opened some Lisp code in KDE's KWrite text editor, and every single default theme highlights parens with a bold font + vibrant colour to make them stand out. Parens in Lisp are supposed to fade in the background, not pop in your face. It was completely unusable, I had to turn off syntax highlighting.

    Always seeking good, minimal, muted colour themes for my editors. I wish we had serious designers to design themes for usability and comfort, and not people that have no business playing with colours.

    I remember a colleague that used to write code with syntax highlighting off, and thought that was an eccentric choice. The older I get, the more I appreciate his wisdom. I'd rather have no syntax highlighting than bad one; at least one would try to make the code easy to parse by its structure alone (shorter lines, comments to delimit sections, etc.)

    • flexagoon an hour ago

      > I have no idea how people are supposed to be productive with non-semantic rainbow vomit themes that are so popular in modern editors.

      That depends on what your use for syntax highlighting is. If you use it to find specific types of code, than yeah, it's probably unhelpful. But for me, the point of syntax highlighting is to just make reading easier by separating different parts of the code with different colors. I have absolutely no idea what each color means in my editor, it just matters that they're different.

    • chrismorgan an hour ago

      Maybe a decade ago, I decided to start a theme from scratch, named bland. Initially, it was just black on white, with keywords bold, comments, macro invocations and lifetime tokens (this was all focusing on Rust) italic, and escape sequences bold italic. I decided to wait a week before deciding if I would add any colours at all. As expected, after that week I made strings red, comments green and numbers blue. Since then, I’ve made number type suffixes light blue, macro-related things orange, and delimiters grey (I should try dropping that one again). But things like making type, async, function*, for, const, of, &c. different? No, they’re all just bold black, no need to try distinguishing between them.

      I also subsequently made a dark variant of it for my website’s dark mode and for occasions I want to use an editor in a dark place.

      The colours involved are all high-contrast, using the RGB channels provided rather than trying to be silly with low contrast: #fff, #000, #c00, #090, #00c to begin with.

      But I have no particular interest in publishing this in a form others can consume in whatever editors they use. Plenty of small tweaks that I develop over time, half for my own Vim syntax files.

    • my-next-account an hour ago

      >Always seeking good, minimal, muted colour themes for my editors. I wish we had serious designers to design themes for usability and comfort, and not people that have no business playing with colours.

      I think Prot's Emacs themes are good for this.

      • sph 35 minutes ago

        Yeah, I forgot to mention them, they're pretty good (though I use the muted colour preset, the default one is too vibrant)

    • embedding-shape 2 hours ago

      > Always seeking good, minimal, muted colour themes for my editors. I wish we had serious designers to design themes for usability and comfort, and not people that have no business playing with colours.

      I want the same as you, but probably also the same as you; I'm too lazy to do it myself. Maybe do all of us an favor, and create that yourself and share it with us? I too prefer no syntax highlight than bad one, and most out there are bad, and you clearly grok a bit more than the typical color scheme creator/maintainer, so you're already 50% there! ;)

      • sph 33 minutes ago

        I have a crappy Emacs theme I built myself, inspired by Jon Blow's Emacs theme he uses on his stream which I find very peaceful to look at, but with a more bluish/indigo hue. It's full of bugs, so not comfortable sharing honestly, but I think it's worth spending an afternoon creating your own

        • peri-cl 4 minutes ago

          > "worth spending an afternoon creating your own"

          It can be very little work if you're not super opinionated. I don't know what counts as a "theme", but I've only ever bothered to set nine faces globally, and that's feature-complete to me.

              '(font-lock-keyword-face        font-lock-type-face
                font-lock-function-name-face  font-lock-string-face
                font-lock-builtin-face        font-lock-comment-face
                font-lock-warning-face        font-lock-variable-name-face
                font-lock-constant-face)
  • wzdd 17 minutes ago

    These rethinking-highlighting posts always start out with the wrong premise. The color for class names in my code is the color all the class names have. After a short time working with the code I would notice if one looked off. The brain is really very efficient. You don’t optimise for random out of context recall unless you really try hard to do so. It says nothing about the efficacy of the scheme.

  • noxss an hour ago

    In my case, colors matter because they help me read faster the keywords of a language that define algorithms such as conditionals, loops, beginnings and ends of functions, returns... without color it is more difficult to send the eye to the correct position. Perhaps it's due to habit or visual memory?

    Good article that gives you food for thought

  • pasc1878 an hour ago

    I found this site very difficult to read and I had to give up as it was hurting – the font is unreadable.

    As for syntax highlighting – I don't like it either.

    I use themes that change colour according to their nesting level.

  • 0xjei 33 minutes ago

    lovely takes! even if the percentage of techies who reads & codes effectively outside coding agents is way way smaller; I think it would be cool to apply this for reading diffs! there might be some adjustments but, I might end up trying to apply principles on top of diffs (https://diffs.com/)!

  • Valodim 2 hours ago

    Good article, enjoyed it. I might give this idea a shot!

    > Comments: these contain high level descriptions (faster than reading the code) and external context (the “why” that reading code can’t answer). This is the most scannable thing in any big code file.

    Not sure about that one, depending on comment culture. Comments are prose and not structured, so to understand their meaning is a lot more cognitive load for me than (most) code. I certainly wouldn't have thought to call them "scannable".

    • Lindby 17 minutes ago

      I totally agree with you about the comments. Code is so much easier to grok. The comments are there as a reference that you can concentrate on if the code doesn't make sense to you.

  • nelsonfigueroa 2 hours ago

    I went through a similar journey not too long ago. I also asked myself "Why does highlighting even need to be in color?" when reworking my blog. I wanted a monochromatic look for my entire site, including code blocks. I noticed code blocks are still very readable as long as there's different tones. I still like pretty colors so I compromised by doing normal syntax highlighting when a code block is hovered over (or tapped on mobile).

    Btw the dynamic highlighting by clicking on the code is so cool. I may or may not steal that idea ;)

  • burticlies 3 hours ago

    I like highlighting only the language concepts:

    Reserved words are red

    Strings are green

    Constants/numbers are blue

    Types/meta-language are yellow

    Anything else is white.

    It’s not too colorful but still gives you plenty of anchors for your eyes.

    • weinzierl an hour ago

      What about comments? Do you prefer comments to stand out or stand back?

      • polyterative an hour ago

        I prefer mine to have low emphasis because sometimes comments lie

  • KronisLV 3 hours ago

    Cool article, really cool website (the font could also be a bit smaller, if it didn't mess with the fidelity), but the grayscale setup just doesn’t have enough contrast for my eyes to reliably pick up on it at a glance.

  • dainank an hour ago

    Maybe I missed it but has he posted his theme anywhere (I assume for VSCode since he mentioned he is using that)?

  • WhyIsItAlwaysHN 3 hours ago

    The continue keyword is also important, or alternatively the condition to run it.

    I often fail to notice it on the first look of some snippet of code

  • cauliflower99 2 hours ago

    Really enjoyable read - well done! I wonder where else we could use an effective, minimal approach that solves the problem at first principles?

  • vova_hn2 35 minutes ago

    Sorry, but I think that this is a completely made up problem. I've checked out the referenced Tonsky's article [0] and for me "colorful" examples are much easier to read than his suggested alternative.

    Also, I had to use reader view for TFA because of this silly pixelated font. Ironic, considering that the article is about readability.

    [0] https://tonsky.me/blog/syntax-highlighting/

    • jdiff 23 minutes ago

      Of course it's a made up problem, most ultimately are. Programming (and life) are full of bike sheds for those with eyes to see them, does that mean they should not be painted?

  • epolanski 2 hours ago

    > Why does highlighting even need to be in color?

    I wrote a vscode extension for effect-ts authoring that indeed leverages this concept.

    It adds underlines and/or bolder fonts to emphasize different colors.

  • tefkah 3 hours ago

    i’m surprise by how much i liked that! also: neutrality website, very tasteful

  • applfanboysbgon 2 hours ago

    I will always yap to anyone who will listen that I think syntax highlighting was a mistake that has cost humanity untold millions of productivity hours. I only highlight comments to distinguish code from not-code, I think everything else is a pretty distraction. Note how nobody ever got the idea to apply syntax highlighting to English or any other natural language, whether in books or on forums. I could believe syntax highlighting helps learn to distinguish things when you're new to programming, but for experienced readers syntax parsing happens as automatically as it does in natural language without any need of colors.

    • atiedebee an hour ago

      The article touches upon this:

      > Unlike prose, where you usually read it linearly, with code you bounce around based on what connected elements you are exploring.

      The moment you are jumping around a lot while reading, being able to understand the structure quickly becomes a major help. For example, dictionaries will have the words in a bold font while italicizing things like the plural etc.

      • applfanboysbgon 42 minutes ago

        The punctuation/indentation already give you structure, all the highlighting does is break up the flow of actually reading. It essentially forces a micro-reset every second or third word rather than allowing you to seamlessly scan to find what you're looking for. It looks unreadable on the blog post because they have an unreadable font that is way too spacey (nothing against pixel fonts, just their particular choice of one...), but it really is way easier to read code if you try no highlighting with a real font.

        I will caveat this on the fact that I use Allman brackets, and have even stronger opinions about that. K&R brackets are cancer and completely destroy the structure of code, so maybe that's why some people feel highlighting is necessary for "structure". With allman brackets, the punctuation guides your eyes to the indentation forming a clean box around each level of code, while if you draw a line from the opening bracket to the closing bracket with K&R style, half the code will be inside it and half outside it, bisecting the natural structure.