1. 15
  1.  

  2. 42

    I’ve never felt that syntax highlighting added or detracted much value. The main value I gain from it is this: When half my file turns a single color, I know where I forgot to close a quote.

    1. [Comment removed by author]

      1. 1

        I use syntax highlighting mainly to separate code into partitions that are easily scannable. Here’s an example of a theme I use for that, that somewhat matched what you wrote above: https://github.com/aerique/emacs-theme-aerique

    2. 37

      I feel this opinion won’t be popular but… this reads like another case of bias confirmation after as little as trying to pay more attention to one’s own code. I’d like some data for a change, not “I felt that I understood my code better”. Otherwise it’s the same feeling you get about your computer being faster after you wiped the dirty screen after a while.

      1. 6

        I think the article is right in asking people to try for themselves. I’ve used Acme for a couple months as my text editor at my workplace. This gave me the opportunity to use it for proper work while keeping Sublime Text at home for hobby projects. While I loved Acme’s particularities (tiling, mouse chords, unix terminal with plan9 utils.. on windows!) I loathed the lack of syntax highlight.

        I didn’t really feel different with my code after taking aways colors, but I noticed both while and after not having it that I was making a lot of mistakes that syntax highlighting would have prevented (unmatched quotes, wrong braces).

        In the end I went back to Sublime, however I’m trying to fill the gap left from Acme with some plugins for tiling and plumbing.

        On the other end, I’m so dependant on my tools now that I’m used to not indent Go code on purpose because I use “gofmt-on-save” as a linter. (if it doesn’t indent it, it’s broken)

        1. 2

          Good point with the indenting. Apart from coloring, that’s the other thing that tells me the parser and I disagree on what I wrote.

        2. 3

          The strongest argument I have is that highlighting English actively makes it more difficult to read. Perhaps this is because we’re used to reading prose without highlighting, but even “lightly highlighted” text like this Sherlock Holmes story is infuriating (scroll down halfway to see some quoted strings).

          1. 22

            I made this comment on lobste.rs last time highlighted prose was used as an example:

            Not a big fan of that image of real lit using syntax highlighting. In programming, we use tons of repeated elements like braces, colons and keywords like for, while, if, import, and hundreds of others, depending on the language. Each if statement will use the exact same keywords. Syntax highlighting can help show us what words really matter and which ones are just syntactical filling inherent with the language. In a novel, each verb conveys vastly different meaning and needs to be read in depth.

            1. 3

              I made a long comment, in that same thread.

              I no longer stand by it. I think it was unnecessarily divisive, and all my complaints came down to “there are no themes I like”. The solution to that is to make one, not to complain about it. And I have found that I do find coloring very useful to add visual texture to code, so that I don’t lose my place in it as easily.

              1. 2

                I tried it and I think there’s something to it. I recommend everyone just try it for a few days.

              2. 9

                I think that comparing the effectiveness of highlighting for spoken languages and highlighting for programming languages is comparing apples to oranges. We don’t read code the same way we read English.

                A better parallel, in my opinion, would be syntax highlighting for a complex mathematical equation, in which case I think you would find it would make it much easier to understand and read.

                1. 2

                  I think using different colors for different variables might be useful with mathematical equations, but I doubt it would help to color variables one color, operations another color, functions a third color, etc., as we do today with code.

                  1. 2

                    Crockford suggested a syntax highlighting where each scope was its own color.

                    1. 2

                      I’ve seen a lot of structural editors for Lisp do things like this over the years. I don’t go that far, but I do highlight parens depending on nesting level, and it can be very helpful.

                      1. 1

                        I actually use a vscode extension that adds this called “indent-rainbow”

                    2. 2

                      In college I used a four color pen. I soooo used syntax highlighting as a way of keeping context like this on paper for many many mathematical constructs - matrices, graphs, equations, what have you. I even have a syntax highlighted regex set on paper filed somewhere in my room still.

                    3. 3

                      Sure but in programming the grammar is a part of the meaning. In english the grammar is usually not relevant.

                      Edit: Amusingly the highlighted english was much easier for me to read. I have ADHD and often lose my place, and the color helped me keep track of which word I was on.

                      1. 2

                        I legitimately think highlighting English makes it easier to read. You can easily pick out the subjects, objects and verbs easily and I think if someone was learning English the highlighting would be very helpful.

                        1. 1

                          You know we actually do use ‘syntax highlighting’ in english in the form of underline, italics etc.

                          It’s just that this particular application of highlighting is awful, since it’s a transplant from code highlighting.

                        2. 2

                          I don’t know about you, but I always feel like my computer is faster after I download some more RAM.

                          1. 11

                            Story time!

                            I was a kid, and I thought I knew stuff about computers. So when Connectix came out with this product called “RAM Doubler”, I giggled. What snake oil! But then we got a copy and lo and behold, I could run more programs than I had memory for! I was totally astounded.

                            Years later, having long forgotten about this, I was in my operating systems class, and I learned about virtual memory. It all snapped into place: RAM Doubler was a kernel extension that implemented virtual memory, which Mac OS didn’t support back in those days.

                            More details: http://www.ambrosiasw.com/Ambrosia_Times/January_96/3.1HowTo.html

                            1. 6

                              IIRC, RAM Doubler also did memory compression in later versions. Maybe they also did black magic with the way memory management worked with contiguous blocks - the classic System had trouble with that. Their later companion product, Speed Doubler, replaced the 68k emulator on PPC Macs with a JIT, which improved performance because almost everything back then was emulated.

                          2. 2

                            Totally agreed. Basically I found myself thinking “I paid attention to my code more” is the crux of the article.

                          3. 18

                            “I got bored so I decided to turn on hard mode.”

                            1. 8

                              I have real trouble with syntax highlighting. It makes everything unreadable to me. I can’t read most websites that display code because of the highlighting. Of course, acme, my text editor, lacks any syntax highlighting.

                              It’s interesting that I didn’t start like this. Before I discovered Plan 9, I used highlighting (usually) just like everyone else. I didn’t turn it on, but it was usually on by default in the vim configuration shipped by Linux and off by default in BSD’s nvi (or simply lacking the original vi shipped in Solaris). But if it wasn’t on already, I didn’t bother turning it on.

                              Now after I stopped using syntax highlighting for many years (close to a decade now), I simply can’t read code with highlighting on. If some colleague wants some help with some code, my first request is to turn nightclub mode off.

                              Oh yeah, I program using a proportional font too (Lucida Grande, 14 point): http://i.imgur.com/XovEU4g.jpg

                              1. 3

                                Project Fortress (a programming language research project) proposed mathematical syntax for programming:

                                Mathematical syntax The idea of “typesetting” the code using LaTeX has received mixed reviews, and many potential users find the issue of keyboarding the extended Unicode character set daunting. Nevertheless, even in its more verbose ASCII form, the syntax of Fortress, especially the notion of treating juxtaposition as a user-definable operation, has proved to be very convenient.

                                I have used unicode greek characters in my code, which I find very helpful, especially when doing scientific programming. My colleagues didn’t like that however and the toolchain was complaining too.

                                1. 3

                                  I think that this might be unpopular and it’s certainly a bit bold, but I often thing that becoming a programmer rather than a mathematician has a lot to do with mathematical notation.

                                  Also I want to point out that there is APL and that despite of my previous statement I’ve seen impressive things done with it.

                                  1. 5

                                    Ken Perlin wrote a small post arguing that one approach is more procedural, while another is declarative (setting up a state of the world and shifting the world while preserving correctness).

                                    As for APL, I wrote k professionally for about a year, and am happy to talk about that experience.

                                    1. 2

                                      I’d be interested in hearing about professional k usage!

                                      1. 2

                                        Me too!

                                        1. 5

                                          It’s been a while, but here are a few observations about k:

                                          • While initially it looks like gibberish, your mind starts picking apart common patterns as “words” and will eventually parse things at a higher level.
                                          • The claims of “flawless code” with respect to the interpreter is basically true. It’s very tightly written, fast, and exact. It doesn’t use a lot of “tricks” like JIT compilation, it’s just solid hand-written code. The only trick that comes to mind is it tracks whether an array is sorted or not, so accidentally doing two sorts doesn’t hurt you.
                                          • Much like lisp forces you to think in recursion, k forces you to think in terms of matrix operations. Instead of doing a depth-first search, you might generate a cartesian product of all possibilities and filter out the wrong answers. Inefficient from a Big O perspective, but the filter loop doesn’t have a lot of pipeline hazards so the result can often be faster. This is probably the biggest key to k’s speed, although I’ve seen claims that the interpreter can fit inside a typical L1 instruction cache which would help as well.
                                          • k programmers really hate loops.
                                          • APL (and by extension k) has the best array index and traversal primitives of any programming language, period. You can slice up and down columns, rows, and (from what I recall) any dimension from a multidimensional array. You can also construct new arrays from an array of indices, much like [x[i] for i in indices] would do in python. The only language I’ve seen that comes close to this power is MATLAB. LINQ might be able to do this as well, but almost certainly in a heavier manner.
                                          • The k sort operation doesn’t actually sort lists. Instead, it gives you the indices of the list in sorted order. You can immediately use the array indexing to give you the sorted list, or you can use the indices for other operations. This is useful to sort a list by a ‘key’ instead of the raw data, or to sort a list and keep other lists in sync with it.
                                          • k programmers are obsessed with code golf. This isn’t as pointless as it seems. As someone pointed out to me, most of the operators in k are roughly in the same order of magnitude with respect to execution time. Since k operators are usually one or two characters, a shorter program usually is faster!
                                          • k is great when you stay inside the ecosystem. Where you have trouble is getting in and out of the ecosystem. At the time when I was working with k it had a terrible command-line UI, hard-to-debug foreign function interface, and you had to work a lot to have fault-tolerant data processing. There also wasn’t a robust OSS library community, so you basically had to do everything from scratch. This may have improved in the past few years!
                                          • A great example of “great when you stay inside the ecosystem, terrible crossing that boundary” is k’s date format. Timestamps in k are stored as seconds since an epoch. Great! Except Arthur Whitney wanted to maximize the amount of useful time expressed by the datatype, so the epoch is January 1st, 2035. This means time is currently negative, and you have to do all kinds of annoying translation to compare to unix time. Looks like kdb+/q uses 2001-01-01 instead, likely to make mental math a bit easier.
                                2. 1

                                  That was really insightful. Thank you!

                                  I am not an acme user, but I considered trying it. What I always wondered about with those self-made commands. Are there like collections of them? I know they aren’t hard to make, but I think a collection could give you ideas, starting points, etc., kind of like a vim plugin or config. Even if I don’t go with huge packages usually (be it vim or zsh), I kind of like ideas that you find while looking at existing stuff.

                                  Or is that generally discouraged for some reason and never fell important?

                                  1. 6

                                    Acme users (all 10 of us) write their own commands when they need them. I don’t know of any collection of commands, sorry, what would be the point? Every environment is different. The philosophy behind acme (plus plumber) is that it’s an integrating environment of arbitrary Unix software (I’m counting Plan 9 as a Unix here), not an integrated environment. It makes it really easy to integrate any reasonably written Unix tool into your workflow, but it doesn’t really provide any such built-in integration by default.

                                    You don’t need any collection of commands to use start using acme though. Usually on every new project I start with a blank environment. I add stuff to it only as needs become apparent.

                                    1. 1

                                      Okay, this is what I expected. I just wondered whether my assumption was correct that people do it that way. Also wondered if there are some scripts, not so much for reuse, but as example, so “smart tricks” on how to do something in a simple way, because I like to read code. :)

                                      Thank you!

                                    2. 1

                                      It’s pretty common to have a+ and a- for increasing/decreasing indentation, and c+ and c- for commenting/uncommenting. Beyond that I’m not aware of any conventions.

                                      1. 1

                                        I have obtained some of mine from other people. Someone on a different lobste.rs thread shared Clear with me (to wipe a terminal).

                                        1. 1

                                          Edit ,d will clear a window (including a terminal).

                                          1. 1

                                            That’s what I used to do, but Clear is easier to middle click, and it keeps my prompt.

                                      2. 1

                                        Holy tag batman! ;)

                                      3. 4

                                        I often program without syntax highlighting and it doesn’t cause problems. If anything i would advocate for maybe a slight graying out of comments, and that is about all.

                                        1. 5

                                          I don’t understand this. Almost all color schemes for editors out there try to hide code comments. I do consider code comments to be essential. If they are meaningless they should not be there in the first place.

                                          1. 3

                                            It’s not an effort to make the comments unreadable, but just to make a clear distinction between what is code and what isn’t.

                                            1. 3

                                              The code is always the source of truth, comments often lie. I’d rather my eye drawn to the code first, as its what I’m working on, then to the comments secondarily.

                                              1. 1

                                                Comments should be treated just as code. If the comment is false the code is faulty. I know that there are loads of examples where this is not true, but just as I think that patches should include patches to documentation, comments should be maintained as well.

                                                This may lead to a situation where comments are used more sparingly in the critical sections of a code block and not like badges where the intern has laid his/her/its hands on.

                                                1. 2

                                                  They should be, but i still haven’t seen a compiler capable of checking comments.

                                                  1. 1

                                                    That’s beside my point, compilers also don’t check documentation. And they certainly cannot check for code correctness.

                                          2. 3

                                            …my coding style changed. I was structuring my source better

                                            My friend switched to using Acme and reported that no highlighting made her a better programmer because she didn’t rely on colors to find mistakes and wrote code that was better organized and more readable. It sorta makes sense that this would happen, but I don’t know if I am ready to try it out for myself. Syntax Highlighting makes code very readable to me and easier to find mistakes. People added that feature to editors for a reason after years of coding without it.

                                            1. 2

                                              I found quite a time ago that full syntax highlighting just distracts me, so I configured vim’s limelight plugin to stretch the highlighting for two paragraphs; which gives exactly what the author describes: limited, conditional highlighting. (limelight was designed with more textual input in mind, but still works great with my python/ruby/bash code).

                                              1. 2

                                                I found it wasn’t necessarily syntax highlighting that I didn’t like, but syntax colouring. To that end, I’ve been using an eink-based theme for several years that has minimal highlighting and no colouring — strings are underlined, comments are shaded, and in the emacs version certain things are bold-faced. For me, I found a lot of colouring was visual noise that was distracting.

                                                1. 2

                                                  Back in 2007 I experimented with an idea I had for a while, a so called fisheye editor: http://apgwoz.com/fisheye-edit/

                                                  The basic idea was that you should see what you are working on now, and only the structure of anything else. As a prototype it was successful, and I liked the way it felt, but I never did try to write fisheye.el to get more realistic data.

                                                  1. 2

                                                    I’ll copy what I wrote on HN:

                                                    This seems to be an over-reaction to overly highlighted code. I work with Erlang in Emacs, and at first I couldn’t believe how much of a Christmas tree my code looked like: every token had its own color, and it was really hard to read. Fortunately, erlang-mode has a setting to reduce the amount of highlighting. I don’t think the proper reaction to a code base that has too many colors is to have none at all: trop c'est comme pas assez. I think many would be happy with some limited highlighting, for example comments, strings, and other constructions that can span multiple lines, incorrect escape codes, possibly-misspelled identifiers, etc. I don’t really need or care that keywords and integer literals are colored differently.

                                                    I should really get off my ass and create an Emacs theme where only a few select constructs have highlighting, and the rest stays with the default color.

                                                    1. 1

                                                      No

                                                      1. 1

                                                        I dont know if syntax highliting makes me understand code better, but I must say that, being really lazy about configuration, I’ve never found that I understood code any less without it.

                                                        1. 6

                                                          It has an opportunity cost. Not highlighting parts of speech except comments and literals allows me to spend limited spectrum on more useful things:

                                                          a) Multiple colors for different kinds of comments.

                                                          b) Highlighting dataflow.

                                                          1. 2

                                                            If anyone is having trouble finding the live demo in the second article, this is the link: http://evanbrooks.info/syntax-highlight/