Live data from Hacker News

Syntax Highlighting Off

robertmelton.com

21–30 of 110 posts

Re: Syntax Highlighting Off

#21
post #19

Earlier quoted context omitted.

Comments are like footnotes in a book: great for adding context to the main text, but they work really well when shoved off to the side somewhere, easily accessible to those who want them, easily ignored by those just into the main text (e.g. Author). Unfortunately, code typography is so horrible in our field that we lack the ability to use the bottom page margin or a side bar for this purpose, so we hack it up with…

Comments also lie. At best, they are a statement that, at the time they were last edited, the author believed their stated facts were true, or might become so, plenty are aspirational, "this is what this function or change to it, which I've not yet written, will do". He might have been wrong, or the code might have changed without updating the comment, the actual running code is the only truth .

I find that comments at the top of functions are helpful when implementing an algorithm found in reference material, especially if they have a citation. At least that way you can check that the function appears to do what the reference material specifies.

But generally commit messages, descriptive symbols, simple logic, short functions, and unit tests are better.

Re: Syntax Highlighting Off

#22
post #18

Syntax highlighting can help structuring your source code when done well and tastefully - coloring your source in all bright colors of the rainbow rather achieves the opposite effect. Personally I am working with a white background, so I try to keep the syntax colors all very dark, so while the different colors can be seen, they should not distract from reading. The correct amount of highlighting very much depends fr…

> coloring your source in all bright colors of the rainbow rather achieves [badness]

Low-hanging fruit is the braindead R/G/B/Cyan/Magenta/Yellow used by some terminals in response to ANSI escape codes: https://sdkmvx.files.wordpress.com/2008/08/ansi-colors.png

In my mind, there's three types of colouring: None, Designed-By-Human, and the aforementioned Eye-Searing-255 (which should really be killed off or at least not be the default for anything used seriously). It's disgusting to open source code using vi or similar and have it presented in Eye-Searing-255.

Re: Syntax Highlighting Off

#23
post #3

Next step: programming using ed. But jokes aside, use whatever environment you like best. For me syntax highlighting is extremely useful. Knowing whether some strings of characters is a type or a variable, or a class type or a basic type makes programming just that much easier. It also helps catching simple typos if something doesn't have the color you'd expect.

I find syntax highlighting is brilliant for focusing on small elements in code. Switching it off is useful for looking at the overall structure of a closure.

Re: Syntax Highlighting Off

#24
I'd freely speculate that 90% of the benefit of syntax highlighting comes from mere lexical highlighting - specifically, making comments, strings and keywords visually distinct from everything else. And even keyword highlighting is very secondary to the first two.

Making comments distinct from normal code is nice because you can easily alternate your focus on one or the other while reading through; and you're not likely to accidentally read commented out code as actual code. You're also not going to forget to close out your comment, for languages with paired comment delimiters.

Making strings highlighted makes it a little bit easier to ensure you're terminated your strings, especially in edge cases around escaping and quoted quotes (for languages that have a choice of quote characters).

Semantic highlighting - distinguishing identifiers based on their definitions - is a seriously niche win most of the time, where you're spending ever increasing amounts of CPU for a marginally actionable hint.

Re: Syntax Highlighting Off

#26
I've had syntax highlighting enabled in Vim for many years without really thinking about it. I just recently started to learn a new programming language (Go) and that got me thinking about the effects of syntax highlighting. I felt that colours would distract me from efficiently learning the syntax of the language so I turned it off for a while, now I'm never going back.

(I really do like having another color on just comments though, code > comments. Separating them makes a big difference when reading source code for me.)

Ended up having to create a Vim color scheme to get what I wanted: https://github.com/ggustafsson/Static-Color-Scheme

Re: Syntax Highlighting Off

#27
post #2

"Reading code is simply more straightforward, smoother and less jumpy. I get the overarching context faster and with less hassle." This makes me think the author might be one of those people who can not superficially scan text very efficiently and resort to.. well, just reading it, word by word. (Is there a term for this phenomenon?)

Agreed, it also depends on what you're trying to do. If you have time to read and comprehend each and every line of code then that's obviously ideal, but time is the most precious resource we have. I find properly implemented syntax highlighting provides a "visual outline" of the code which I can use like a table of contents or index. This allows me to save time and focus for the segments of code that require my full attention. Sure it makes things more "jumpy" and sometimes I have to backtrack to get context, but I find it makes the overall process much more time-efficient.

I'd also point out turning off highlighting may produce a false perception if the color scheme you're switching from is mediocre or worse (as most of them are in my experience). To a starving man McDonalds tastes like heaven. Properly implemented syntax highlighting shouldn't be distracting in the first place. If you're using syntax highlighting and have trouble reading code line-by-line then that's just a sign you need a better color scheme IMO. I switched from some random theme I found online to solarized-dark a couple of years ago and found it made the reading experience much smoother.

At any rate I'm glad he's found something that makes his programming more productive and enjoyable, but I would avoid categorizing it as objectively better, as the author tries to do.

Re: Syntax Highlighting Off

#28
What I've once read is that the advantages for syntax highlighting are biggest for beginners (in general or in that programming language). This seems logical when looking at what syntax highlighting does: colouring differently according to the token type. Beginners might have more problems finding the borders of what belongs together and what kind of token something is.

If we compare this with classical text, we won't have any typographic help for the inner structures of sentences, maybe simply because colouring different types of words differently was quite hard. Typography there is used for the outer structure. Mostly vertical space is used to separate paragraphs. This is also used in programming. However making headlines bigger and use a different type isn't used in programming. Programming uses indentation instead. It is pretty obvious that it's this way because of the limitations of the medium in the beginning. Also it's not as easy as classifying tokens.

Re: Syntax Highlighting Off

#29
I don't understand the reasoning behind this. What possible benefit could you get from turning off all syntax highlighting?

It's useful to distinguish between language keywords and user specified names. Being able to visually ignore one of them, while focusing on the other, is a tremendous benefit. It cuts down the number of things you need to hold in your head at once, by half.

It's useful to distinguish between local variables and instance variables. It helps to better understand the dependencies that exist between a method and other methods/state.

It's useful to distinguish between mutable variables, and constants. It tells you at a glance how something is being used, and the pitfalls you need to watch out for.

Turning off all syntax highlighting destroys all of the benefits above, and I can't think of any notable benefit you would get out of it.

I guarantee you, whatever "upside" you think you're feeling right now, it's simply the novelty effect. This is a very common phenomenon in AB testing. Often times, you see an initial improvement, simply because users respond positively to the initial novelty of something being different. I guarantee you, if you continue to work without syntax highlighting for 6 months, and then turn it back on for a few weeks, you'll realize how much you actually love it.

Re: Syntax Highlighting Off

#30

What I've once read is that the advantages for syntax highlighting are biggest for beginners (in general or in that programming language). This seems logical when looking at what syntax highlighting does: colouring differently according to the token type. Beginners might have more problems finding the borders of what belongs together and what kind of token something is. If we compare this with classical text, we won'…

It can also help when jumping around between many different languages, especially when they are similar.
Post reply on HN