Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



One of the most important benefits of syntax highlighting that no one in this thread seems to be discussing is the highlighting of syntax errors. That is the number one benefit of syntax highlighting for me. It immediately shows me where there's a problem in my code (like if I haven't closed parenthesis or quotes) and keeps me focused on "completing the thought", as it were.

This is also a reason that I don't like using editor features that automatically close parenthesis or quotes when you type the opening pair. That may make the expression syntactically correct, but semantically incomplete and the burden will be on me to notice, since syntax highlighting won't help me then.


Highlighting of errors is, for me, something distinct; a background parse / compile process that reports line numbers is sufficient. It doesn't need deep integration with the editor. A keyboard shortcut to go to the next error and you're pretty much all set.

I'm also not a big fan of overly eager syntax checking because I tend to compose abstractions on the fly, leaving a statement incomplete while I flesh out a dependency, or vice versa. Syntax aware indenting usually breaks badly in this situation - I generally prefer dumb indenting, with an opt-in block or file format option for where I want to fix code over a large area. I've had big fights with Emacs over this; it almost always does the wrong thing by default, whether it's indent location, continuation indent, mixing tabs and spaces in the indent, etc. About half my .emacs is replacement indentation functionality and configuration per mode.

I also don't like auto-completing parentheses, because it puts text ahead of the cursor on the current line. That's a PITA because the editor almost invariably doesn't know when I want to complete the expression or how. Eclipse is the worst at this (it's actually not possible to turn off in a sane way). It interprets RET as completing the expression when I want a line break inside the parens, and I'm constantly having to go back and forth to work around its mistakes.


Autocompleting is by far my biggest pet peeve in modern IDEs. With default settings in Jupyter, for example, typing """ immediately creates another """. Another great one is when autocomplete tries to be vindictively clever and often deletes your open parentheses if you delete its closed parenthesis. Complete concentration killer.


> It immediately shows me where there's a problem in my code (like if I haven't closed parenthesis or quotes) and keeps me focused on "completing the thought", as it were.

Funny, because I dislike having syntax errors highlighted for the exact same reason. If I'm typing new code, I like to keep my thoughts on the reasoning behind what I'm typing, and leave it until later to "clean up" the code and get it syntactically correct. Having big red highlights around code that I haven't finished writing yet is a huge distraction... the editor seems to be beckoning to me: "Stop typing and close that paren! Why are you still typing! It's not corrreeeeect yet!!!". And usually it's enough distraction to cut off a good train of thought.

It gets worse when the editor starts complaining about full compilation errors, like calling functions I haven't written yet. When I'm in a more "creative" part of my coding (like when I'm doing lots of brand new functionality), there's a certain ordering of what I write first and what I fill in later, and having an IDE yell at me the whole time is just tiresome.


Alongside the errors which I agree with and mentioned elsewhere one of the things I really like about intellij (sure others do it) is you can highlight the variable under the cursor in different colors (for read/write), I have mine set to dark red for writes and green for reads, That really helps as you jump around code as you can stick it on a method and it highlights all calls to that method in the code.


The author does mention that, though, when he's talking about the pros and cons in the very beginning of the article:

> What do I miss? Syntax highlighting hinting that I made a dumb typo (importance is directly proportional to compile time or speed of running syntastic).


I wasn't aware there was anything more to syntax highlighting than what you are calling "lexical highlighting" - what I think of as "syntax highlighting" consists of coloring comments, string literals, and reserved words differently than identifiers or punctuation marks. So, I gather that there must be some editors which use more complicated schemes; can you point me at an example?


this, for me, is a frustrating aspect of programming from a user's perspective

when someone builds something they often 'hard code' their own specific interests into the thing

so let's say i am like you, and only want the comments highlighted.. if the highlighter i am using fails to allow me to alter it from the user side of things i'll have to dive into the source

if it is closed then i have to take the time to build my own wheel

if it is is open, but after investigation i find the functionality is hardcoded, piecemeal, and highly specific then i have to take the time to build my own wheel

this is an overly simplistic example of what i am trying to illuminate but from a user's perspective there is a huge difference between these equations:

    print(51)

    n=3*17
    print(n)

    a=3
    e=17
    print(a*e)

    a=sys.argv[1]
    e=sys.argv[2]
    print(a*e)
for highly configurable designs just pulling flags from the command line will get out of hand quickly but it would be superficial to have a function that allows the user to see the programs state and alter it to their needs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: