Hacker News new | past | comments | ask | show | jobs | submit login
Turning off syntax highlighting (dudzik.co)
172 points by dudzik on Nov 6, 2016 | hide | past | favorite | 184 comments



Slightly meta: Turning off the syntax highlighting entirely seems a bit hardcore to me, however, I always read each commit I do via git diff / pull request view, which does not have syntax highlighting (other than red/green for removals/additions), and I always strive to make the diff look good for each commit (which means, doing one thing at a time in each commit, and making sure it reads well).

Unfortunately, not everyone I work with reads their code (yep, they write-commit-push-and-forget!) which sometimes makes code review a not so nice experience.

Please, please, read your diffs before sending code for review.


I agree completely. On that note, I also consider `git add -A` to be horrible practice. Adding files manually makes you tons more aware of what changes you actually made, and also prevents you from accidentally adding extra files you don't want.

I also recommend people to look at the Linux kernel git history for good examples of how to use git well. Even if you have no knowledge of kernel code (and most people don't) it's still extremely clear how each commit makes a single change and is fairly easy to review. Now, the Linux kernel has the luxury of being able to demand people fix their commits, but that's not to say you shouldn't strive to reach similar states in your commits.


    > I also consider `git add -A` to be horrible
    > practice. Adding files manually makes you tons more
    > aware
Agreed, but I take it further than that - I always use `git add -p` because it forces me to read through everything, and make everything in the commit deliberate.

Even if you think you just made a slight change to a file or two and definitely want everything, you'd be surprised how often it lets me pick up some aesthetic change, comment change, or dependency version bump that's completely unrelated to the commit message I'm about to write.


I am in the other extreme: I always use `git add -A` (but I read the diff before) and avoid doing more than one thing in the first place (which would make me want to use `git add -p`). IMO it is an antipattern to do bazillion changes at once, and then do several commits out of it (unless you really know what you're doing) - because you commit a state of the repo that (probably) never existed. I prefer to do change, commit, do change, commit, and at the end do interactive rebase and perhaps squash some things together.


I understand what you're getting at, but unfortunately I just don't write code that way (And I'm not really sure I know tons of people that do). I always end-up making changes or realizing things halfway into working on something. That said I do understand your point, generally what I do is commit 'logical' parts of my work (Generally using `git add -i` to commit individual chunks), and then when I'm done I checkout each commit to test it compiles on its own.

The fact that `git` makes changing your history around easy make this workflow work fairly well without too much extra overhead to achieve a clean history. I don't disagree that doing it right the first time is really the best way to do it, I just don't find that it really works out that way in practice.


True, sometimes I realize I need to do something half-way when doing something else, then I do a "WIP commit", do another thing and commit that thing (sometimes in a separate branch forked off master), then perhaps reorder commits if needed, and go back to continue working on the previous thing (and amend the "WIP commit" once done)

The tricky thing is that when doing several things without committing, sometimes you can end up in a state of the repo where you can't split the work done into nice commits anymore (because you might have modified same part of code multiple times).


I usually have a paper and pen at hand, all non-current work goes there — empty circle and todo text. It was my bad habit to patch things immediately at sight. That way I sometimes missed part of context, either of main task, or secondary, depending on complexity of both.

Maybe this step-by-step working scheme was influenced by svn that cannot commit partial changes, but it seems a good practice on its own, especially in total refactoring.


    > and avoid doing more than one thing in the first
    > place (which would make me want to use `git add -p`)
Yep, I still _avoid_ it, but I'm often surprised by something that slips through - e.g. a typo in a comment that I just changed as I read through - but a comment somewhere totally unrelated to the present commit.

Maybe your better at avoiding it than I am, but I find it to be easily done.


If I do such minor corrections, I usually commit them immediately (via `git add -p` or better `git commit -p`), so they are out of my way.


  git status
  ...
Yep, those are the things I changed

  git add -A
  git status
Yep...

  git commit
...editing in VI... :wq

Mischief managed.


Yep that's the way to do it. Assume that you want to add all files (which is usually the case) and then just double check before. This is my practice.


Don't you always have commits chains like "add debug printfs" "fix bug" "remove debug printfs"?


That's a scenario for branch-then-cherrypick :)

Branch, write test to expose bug, add debug aids, fix bug, switch branch, cherry pick the test & fix, delete debug branch.


Or just `git rebase -i origin/master` and delete the unnecessary commits without additional branching.


I have these in my WIP branches. When I’m ready to merge, I squash out some of the smaller commits, and then merge without fast-forward. Reduces noise and keeps a clear history of groups of work, at the expense of very cheap branching and local rebasing operations.


> because you commit a state of the repo that (probably) never existed

The state doesn't exist in the repository until the code has been committed - so your statement is a little backwards. Sure the code might never have only had that edit in it, but the repository has no changes until a commit is made.


What the commenter means is that one might accidentally select some invalid or non-sensical set of partial changes (that won't compile or run) in an effort to create a logical progression between state A, "no feature", and state B, "feature is complete".

If a bug is found, the invalid state of the intermediate commits might make it harder to isolate the change that caused the bug.

That being said, I generally use "git add -p". I've gotten accustomed to trying to have clean commits. Although, sometimes the changes have enough complexity that breaking them up becomes too painful and I end up with a few messy commits. Such is life.


I think this is a good practice; it's always easy to let your attention lapse and skim over a line when you're reading the full diff. `git add -p` is nice in that it explicitly requires you to ack each change.


I recommend using `git commit -p`, which is a shorthand for `git add -p` followed by `git commit`.

Then, `git show` before you do `git push`.


I just don't understand why people use the git CLI. Git is too powerful a tool, using the CLI limits one of two things: your capabilities, or your productivity.

Often times I see my coworkers screwing around with git trying to review diffs and commit their changes. One of two things happens: they spend longer than they should doing it, or they do it haphazardly. Sometimes they get it wrong.

Just use a GUI.

I use SourceTree and often find myself committing individual lines or chunks in my files instead of the whole file. I'm confident the average git CLI user doesn't even know this is possible. I can do massively complicated commits with ease because I can see every single line that has changed right in front of me.

I just don't understand the fetishization of source control via CLI. In all likelihood it doesn't make you more productive, and it's probably less accurate unless you really know you way around git.


As a counterpoint, every time I've tried a git GUI (I've tried lots), I end up bashing my head against it within a few minutes. They usually make very basic things easy and anything even slightly outside the box basically impossible.

I'm much more productive using a couple of git commands that I can type in a few seconds, rather than hunting for things in menus and dialogs for ages.

> committing individual lines or chunks in my files instead of the whole file

That's really git 101. I'd expect if you haven't learned to do that via the CLI then maybe you gave up too soon and jumped straight to GUI? `git add -p .` is very easy to use.


[GUIs] usually make very basic things easy and anything even slightly outside the box basically impossible.

Whereas in the CLI, complex operations are difficult but possible; trivial operations are also difficult but possible. :)


did you try magit?

Maybe it is of limited use for non-emacs users, but imho it's a fantastic way to use git with a perfect balance between making simple things very easy to do and allowing (almost) anything you can do with the CLI while providing excellent visual feedback.


I also found the git plugin [1] in the Sublime Text Package Control repository to be rather useful. The basic idea is similar to magit, with the (subjective) upside of avoiding the crazy Emacs hotkeys.

That said, since I discovered Spacemacs, I'm also enjoying using Magit - the "evil" control scheme for it is great, too.

[1]: https://packagecontrol.io/packages/Git


magit is a marvelous piece of work indeed, and the thing that keeps me going back to Emacs every time I get curious about some other editor.

But yeah, I picked it up after quite some time working in Emacs, and the keybindings feel natural. Perhaps it would be very different for somebody new to Emacs.


i use a gui for two things:

1. gitk is the handiest way to undo the occasional accidental commit ("reset index, leave working tree untouched"). yes, i know there's bound to be a CLI way; no, i can't be bothered to look it up and remember it when i have gitk right there and it's not a mainstream use case.

2. git-cola does interactive commits way better than the console interface does.


> I can do massively complicated commits with ease because I can see every single line that has changed right in front of me.

You mean `git diff`? I'm sure it comes down to a matter of preference, but claiming that using git from a command line slows you down or limits your capabilities only makes sense if you rarely touch a command line (a bit strange for a developer). Plain old git from the command line is functional and actually quite user friendly. Add your own aliases and some kind of git shell and you can fire off a complicated commit as fast as you can sensibly review your diff — all without lifting a finger from the keyboard.

GUI git tools are nice for visualizing feature branches, but for the basic day-to-day workflow the CLI is much more productive.


> Git is too powerful a tool, using the CLI limits one of two things: your capabilities, or your productivity.

Surely the exact comment, with the roles of 'CLI' and 'GUI' switched, could be made without anyone necessarily noticing. The anecdotal evidence of what works, and doesn't work, for you should not, I think, be regarded as any particular evidence of what does work for anyone else, much less what can work for everyone else. (As has already been pointed out, your child posts are full of responses from people with other experience.)


Agree with this 100%. If you can do everything you want on the CLI then more power to you, but in my experience people using the CLI for diffs/staging include unrelated code in their commits at a much higher rate. I checkout/branch/pull/push in the CLI, and use Git Tower to diff and stage.


I would wager this goes beyond just `git`, and is more a statement about CLI vs. GUI, which IMO just comes down to preference, and how much you're really willing to learn one vs. the other.

There are definitely people out there (I've seen them) that would be better served with a GUI because they really can't be bothered to learn how to use the `git` CLI well (Or just use `git` well in general). But at the same time I'm tons more productive with the CLI vs. GUI.


> I just don't understand why people use the git CLI. Git is too powerful a tool, using the CLI limits one of two things: your capabilities, or your productivity.

That's fine, but on the other hand, a typical GUI limits both your capabilities and your productivity.

About the only interface I prefer over git CLI is magit in Emacs. It's unlike your typical GUI, because you don't have to click at anything (keyboard-operated), and it exposes like 99% of git inside a well-thought-out text-based UI that adds just the right amount of interaction and editor integration. Using magit is incredibly efficient, much faster than even using CLI git.

> I just don't understand the fetishization of source control via CLI. In all likelihood it doesn't make you more productive, and it's probably less accurate unless you really know you way around git.

If you don't know your way around git, chances are you're going to seriously screw things up via GUI and you'll have no idea what happened or how to fix it. Starting from CLI is a good way to actually learn the tool, which I believe is crucial regardless of what interface you'll eventually be using.


> I'm confident the average git CLI user doesn't even know this is possible.

Your sibling commenters disagree.


In that case, I'll support his conjecture by admitting that I didn't know that was possible. I'm a pretty average git user, if not actually using it slightly more than my peers (many of whom are only switching from subversion to git within the last 3-4 years). But the rate at which I become more proficient in git is extremely slow - you have to go out of your way to learn more about git most of the time. Maybe a GUI would help in that particular aspect, since I could see unknown options and experiment with them.


As someone in pretty much the same boat, try SourceTree or the like. I still use Git from the command line, but it really opened my eyes on what Git can do.


I agree with this 100% when it comes to creating commits. It makes it easy to create sensible commits with only the changes relevant to the individual commit. You can see what's staged and tailor it quickly. I'm a heavy terminal users and I agree that in general committing from the CLI seems like using the wrong tool for the job.

That said, there's a lot you can't do easily or at all from the GUI. Rebases, surgically reverting a series of commits from a bad merge, re-writing branches, blame, bisect, reviewing the history of a single file, checkout of a specific version of a file from a previous revision; there are a lot of things that I can do easily from the CLI that I don't know how to do or don't care to do from a GUI.

Use the right tool for the job. The GUI is great for common tasks and the CLI is great when you need more power.


No gui that I have seen can deal with the GIT workflows in an efficient manner. Most GUIs are slow. Rethink GIT workflows and make them worse. I only use a GUI for this: - GitX for adding and reviewing files to a commit. (partial commit support is also very nice).

the rest is command line git.

With command line completion is pretty good and fast.


I used to be in your camp before I discovered git add -p. Allows you to interactively pick which hunks to stage. SourceTree essentially replicated the same workflow in a nice GUI.


Yeah that's what I used to think but you have at understand that typing and keeping your fingers on the keyboard is often way faster than moving around and clicking various regions of the screen.

Then what happens when they update their GUI? Oh you have to learn it all over again.

That being said, I do on occasion open a GUI if I have to do a complicated merge or something like that but for basic operations why would you need it.


Unfortunately, nome of those neat git GUIs work on Linux...


If you use Emacs, check out magit. It's not really a GUI but it is git integrated into emacs so you can do all the usual functions, view diffs, write commit messages, etc. all from within emacs.


SmartGit is wonderful - I've used it for years - and it works on Linux, macOS, and Windows.

http://www.syntevo.com/smartgit/



Propietary, requires an account and mergetool is behind a paywall (although this is not as significant). Ouch.


> On that note, I also consider `git add -A` to be horrible practice. Adding files manually makes you tons more aware of what changes you actually made, and also prevents you from accidentally adding extra files you don't want.

I use `git commit -a` a lot, but only after checking `git status` (or `git diff`), which is probably my most-used git command.


Those two A's have completely different meanings though (add all, commit amend), not sure I understand how it's relevant to the parent?


Grandparent is correct: "git commit -a" is --all, not --amend.


I use `git add . -p` which allows me to 1) selectively create my commit, and 2) re-read what I've changed to understand it all better. I agree about wholesale adding, but of course there are exceptions when you already did `git diff` Or something.

Side note: `git status` is not a good means of "knowing what was changed". I see others use it constantly (doing git status -> git add . -> git commit) and it'a sloppy IMO.


I get a lot of (good-natured) crap from other developers because I always use a graphical tool to view my git diffs and make commits. I realize that there are console tools like git interactive staging that provide similar functionality, but honestly I just like having a dedicated windowed application always running that is always the gateway for my code.


> I get a lot of (good-natured) crap from other developers because I always use a graphical tool to [...]

One of my colleagues uses PyCharm, while at the same time using Vim somewhere else (for both Python and not Python). This frustrated me a little every time he asked me to his terminal in a similar fashion I'm annoyed by somebody using GUI for the simplest task I could do in a single command. In both cases I try to keep comments to myself, at least now that I'm a little wiser than I was five-to-ten years ago.

It takes a lot of patience not to throw such "good-natured crap" if one is proficient with more-basic-yet-powerful tools. It needs wisdom to recognize that people do things their own way because it's more effective for them at the moment, and it's hard to change one's habits on a whim at arbitrary times. It gives me much better results to call others to my terminal to show them some interesting thing; they are in much better condition to learn a new Vim command or CLI tool (this way I successfully exposed two colleagues to AWK, what I planned for a long time).


I always do `git add -p` and `git commit -e -v` so that I know exactly what's in the commit


I'm amazed someone wouldn't read their diffs, just for their own sanity. It's a great summary to remind yourself what you just did to resolve an issue. And what if your cat just walked over your keyboard while you weren't looking? Your diff will tell you this. Silly but meaningful example.


>Slightly meta: Turning off the syntax highlighting entirely seems a bit hardcore to me, however, I always read each commit I do via git diff / pull request view, which does not have syntax highlighting (other than red/green for removals/additions), and I always strive to make the diff look good for each commit (which means, doing one thing at a time in each commit)

...alas, some projects require 1 commit per pr, max...

...then again, if you do a 1:1 commit:change as default the rebase msg is much easier to structure :)


I prefer doing this with 'git gui'. It's standard and is very simple to use. What is important you can easily select chunks or lines to stage or unstage.


Learning to this both after writing the code and being able to plan what chunks of works I do when is a game changer and really useful when you work on a team.

I sometimes find waiting until I am done working on something to break it up into small commits can be a headache.


Agreed. The first thing the older guys taught me at my first internship was `git add --patch`.


I always use `git commit -v` (with alias).

You get the diff in the editor when you write commit message.


I'm just trying to convince folks to actually write commit messages. :) I don't think anyone is relying on diffs to find bugs. Do they?

Similarly, before doing something complicated at work, please talk about it with a coworker first. Last thing I want is to try to decipher a complicated piece of code without a good motivator as to why I'm doing so. Advanced warning is a great motivator.


I do this, but not mainly to find bugs, though on rare occasions I do. I almost always find something, e.g. stylistic aberrations, overzealous changes from an intellij refactor, debug statements I forgot to remove, part of another change I'd thought I'd stashed but somehow ended up in the commit. It blows my mind that anybody would not read their diffs.


Fair. I try to do this. I still make mistakes, I'm sure. This ultimately comes down to a "good intentions." Would be neat to make a mechanism out of it.


In the first few sentences he expressly states why you want highlighting:

> I couldn’t skip through the source that fast anymore and it became harder to read

Which, yes all the modifications to style (which is only his own code by the way) helped factor out. But I bet he'd be even better now with highlighting that he's made these additional changes to his style.

I worked for years without syntax highlighting. I am much more efficient with it for exactly the reason quoted. To each their own, but having visual cues to help is not a bad thing. I want my job to be easier.

I used to program black on white, then I was converted after jetbrains came out with an excellent dark theme with huge color variants that make code pop even better.

I'll never go back; I want my work and job easy, not made harder.


This was my thought - he's altered his style to be more readable without syntax highlighting, which is all well and good for him, but doesn't necessarily translate to it being more readable with syntax highlighting, and so is not necessarily a grand thing for his teammates who still use it.


> which is only his own code by the way

Yes, working in a team is definitely a different endeavor. If your teammates or organization aren't open to changes to the style guide then I wouldn't recommend turning syntax highlighting off.


I predict that in a few months the author will turn a toned down version of syntax highlighting back on. All the advantages he stated were the result of disrupting his previous practices. Doing that forces you to reconsider how you do things and end up improving your skills. But they are learned lessons, not some mysterious side affect of less color.


That's what robertmeta did[1], but when I turned off syntax highlighting I left it off.

[1]: https://www.robertmelton.com/2016/04/10/syntax-highlighting-...


I turned off syntax highlighting several months ago and never wanted to turn it back on. Scanning the code is now as good as it was before. And understanding und structuring the code got better because I'm no longer distracted by unimportant parts of the code.


No thanks.

The last time I could bare not using syntax highlighting I was still on MS-DOS.

Since Turbo Pascal 7 (released in 1992), syntax highlighting is a must have on my programming environment.

But I understand when we are talking about vim, people prefer an hardcore experience.


I don't think that's what "hardcore" means to a vim user. Vim is all about convenience for me.


Huh, I thought being "hardcore" about vim meant writing your own syntax highlighting rules. (Which isn't that hard, though vimscript does have some weird quirks.)


Vim's syntax coloring is more powerful than what I have been able to find in other systems. It can handle nested constructs quite well. If you have a situation in which two languages can be embedded in each other.

I am using Vim dynamically, calling it out of CGIT. For example:

http://www.kylheku.com/cgit/txr/tree/genman.txr

When you access this file, CGIT runs a syntax highlighting shell script where you can hook in multiple approaches (e.g. based on file suffix). I hacked this script to run Vim via Expect, to load the text and save the HTML with :TOHtml.

As you can see, the TXR pattern language and TXR Lisp are nicely separated in the output. The identifiers are colored differently---even in cases when they are the same! Look for a purple (do ...), which is a directive in the TXR pattern language to enclose and evaluate a bunch of Lisp, and green (do ...), which is a totally unrelated construct in TXR Lisp: one of the forms that support explicit partial evaluation.

When I'm coding in TXR, Vim is quite accurate in identifying mistakes like string literals not being closed and parentheses not being balanced and such, or various tokens being malformed and whatnot. It can figure it out in spite of levels of nesting. It significantly reduces such errors.


I first learned C on VMS.

When I could use Turbo C on my own computer in the 1990s, syntax highlighting just came along for the ride. I learned vi from Watcom. I used vim. I wrote in perl, and PHP. I also learned Emacs. I wrote in Common Lisp. Syntax highlighting just stayed on.

And then I saw someone do something I had never seen before, and I wasn't sure how to do, and I noticed they weren't using syntax highlighting.

So I turned it off.


Why stop at imitating that amazing coder's choice not to use syntax coloring? Dress like them, and adopt their tastes in music, political views and sexual orientation too.


Did you have any thoughts of your own about the before/after experience? Or did you simply imitate them on the basis of learning an unrelated trick?


Yes. Maybe. I don't think I was thinking about it that way. I think it was more like "look at how readable this is[1]", and when I opened it on my own computer all the bright colours were suddenly very distracting so I turned it off.

I would sometimes use ed to make changes to programs since I can see what I was working on before I needed to make a change, so I don't think it was doing anything for me, but at the same time I don't think I ever thought about syntax highlighting until I tried to work with dense code.

I do try consciously to improve myself, but nobody knows how they program and how to get better. The only strategy that has worked reliably: If I see someone do something I cannot do I try their methods until it makes sense in my own mind.

I've tried to write about this previously[2], but most programmers are hostile when seeing someone do something they can't do, rather than just trying it, they make up all sorts of reasons why they don't need to --"it's unreadable"[3] is extremely common, but questions abou[4] is a new one on me.

As it stands: I don't understand syntax highlighting. I'm pretty sure that syntax highlighting doesn't do anything for me in the best case. Maybe. But is it bad? Is turning it off necessary to being a better programmer? I got better when I turned it off, but it really might be a coincidence. I don't know.

[1]: http://kparc.com/b/a.c but not exactly.

[2]: https://news.ycombinator.com/item?id=8476294

[3]: https://news.ycombinator.com/item?id=8477064

[4]: https://news.ycombinator.com/item?id=12887021


That seems pretty reasonable - if you can see that someone else can do something you can't, and you don't know how, then there's no harm seeing what they do differently to you and trying that just in case. Correlation doesn't imply causation but it does suggest the possibility.

I know I prefer a much more muted colour scheme now than I used to. I still like my syntax highlighting but it's more hinting than glaring RGB confetti.


You understand wrong. When that author typed ":syntax off" in Vim, he was actually disabling possibly the best syntax coloring engine there is.


On that I disagree. I am a long time Vim user and I always enable vim mode wherever I can. But compared to IDEs and editors that use compilers for hilighting, vim is pretty poor.


I don't understand how that make pjmlp wrong in any way?

Being hardcore doesn't imply that the syntax coloring is bad.


IMO vim has one of the best syntax highlighting of all coding environments.


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 have 2.5 major distinctions made in my syntax highlighting, and it's common to almost all languages for me:

Comments are a shade that's near the background: I can read them if I focus on them, but otherwise they're not present when I'm reading code

Strings are a colourful colour, because the next visual distinction I want is between what's an operation or name, and what's data or literal. Numbers don't get this treatment because they're sufficiently obvious on their own.

The base text colour has a small distinction between keywords (darker) and everything else (lighter).

Sometimes I'll pull in another colour if I'm in something like Python for things like decorators, to create a distinction between code and meta-code.

This takes care of 95% of the visual distinguishing that's useful, and the rest is noise that adds cognitive load to track. As a bonus, because it's common to all languages in which I work, switching is easy because almost every language breaks down nicely between these categories.


If making comments invisible is at all helpful, they’re being seriously misused. Comments are supposed to explain what’s going on, and thus make things easier. Hiding them should be very counter-productive.


As pYQAJ6Zm says: they're not invisible, but when I'm looking at code, they're easily ignored, and when I'm looking at comments, they're easily located. Using solarized dark, the background is Base 03 'bright black' (#002833) and the comments are Base02 'black' made a bit lighter (#004f62).

Comments are for holding details: I shouldn't need them to understand code, at least superficially/structurally. But they should be there if I need to drill down on something a bit, and making it so that focusing on that extra detail is easily skipped or applied makes the overall code reading much more fluid.


I do the same thing. It’s not as much hiding the comments as making them less attention-grabbing when they are not needed.


Not this again

"We should remove all color from traffic lights and make people remember which position is what"


Somewhat of a false dichotomy, no? I'm not hurrying up to remove syntax highlighting of source, but I also don't particular care that I don't have it in email snippets. Or in many books. (Of course, now I need to go verify that my books don't actually have some form of typographic trick for source code. Other than tt.)

I have gone for a more reserved theme in my editor lately. Currently on solarized again, but probably going back to zenburn soon.


Surely this would make people slow down and pay attention or you know just crash more.


Right, but realistically they'd just crash more and then what's been achieved? Some of us get to feel smug about how the daft plebs aren't hard-core enough to navigate without colored traffic lights?


not OP but I believe that was the point he was making


There was an article shared here on HN some time back about the guy who got one Dutch town to remove the warning signs on its traffic circles.

Accident rates dropped sharply.


The difference here is that on a traffic light the colors are important and inherent to the traffic light's functionality.

This is not true in source code. Syntax highlighting "helps" you to spot strings, numbers, keyword arguments etc. faster. But normally this is not what programming is about.


> The difference here is that on a traffic light the colors are important and inherent to the traffic light's functionality.

They're really not. See also: millions of red-green colorblind people.

The top one is stop, the bottom one is go.


I think you've done a better job supporting the other side. The direction and order is important and inherent to the traffic lights functionality, not the color. The color merely helps identify state. Colorblind people can drive fine without knowing which is red and which is green.

The point of colors in syntax highlighting, to me, is not to have a handicap, it's to read the code at the fastest speed possible. No one who is so new to an editor or a language should have the unrealistic expectations to understand the colors and read at full speed in their first hour of gazing.


When you talk about reading the code then you mean parsing? When you think you gain productivity by parsing the code in strings, variable assignments, function calls, numbers etc. then syntax highlighting is good for you. But I don't think a programmer gains anything from this.


That would be fun. There are a significant amount of people in my building that don't realize the top light means the elevator is going up and the bottom light means it's going down.


About 8% of the world is color blind, so having standard positions on traffic light is indeed very important.


Actually instead they tint the traffic light colours to make them distinguishable to colour blind folk.

It's actually really uncommon to be completely unable to see colour; mostly it is just a problem to be able to distinguish colours.


Syntax highlighting only helps with the easy stuff. It doesn't do anything for

    std::array<std::shared_ptr<Window>, max_window_count>{};
or

    s.lines()
        .map(|bline| UnicodeSegmentation::graphemes(bline, true)    
            .collect::<Vec<&str>>())
        .map(|line| wordwrapline(&line, maxline, maxword))
        .collect::<Vec<String>>()        
        .join("\n")
because nothing there is a language keyword.


> because nothing there is a language keyword

What editor are you using where the highlighter doesn't identify user-defined types, member functions, namespaces, local variables? Maybe you don't realize it has these capabilities because it's configured to highlight them with the default?


A highlighter in Visual Studio is able to distinguish (at least) preprocesor definitions, variables and class names.


I tried this multiple times over the last few years and it always didn't matter. It's not making a measurable difference but it looks less pleasant and I rather look at pretty things.


I also don't find the syntax coloring to make a big difference for me. What does though is the semantic feedback/navigation in the IDE.

When I joined a Java shop for the first time I was all gung-ho about sticking to my 80x24 terminal and emacs and to heck with the point-and-click crowd who couldn't do their work without a graphical UI. Then my new manager got me to try Eclipse for a week. I humored him and discovered that I was an order of magnitude more productive with Eclipse's semantic features like on-the-fly compile error underlining, code autocomplete, and navigation. It really was a humbling experience.


I found most of syntax highlighting easy distracting. But I couldn't turn it off completely as it felt weird. What I did is I modified theme who's colors I loved the most, so that it highlights less things, so that only some keywords would be highlighted like (break, return, for, if, etc). That way it helped me as screen didn't look to colorful, distracting and it didn't strain my eyes as before, but still providing some necessary information that pops out, to help me see the structure of my code better. But that is just me. I think I am not yet ready to give up syntax highlighting completely, but who knows, maybe one day. I am surely making progress towards that.


Author should provide some before/after code to show how it affected his coding style.


> Conditional syntax highlighting

I think that's the right approach. Different situations afford different tools. In normal usage, reading only in a single color is a real relief to me; but of course it's typically easier to find missing delimiters and such with syntax highlighting.

I've had this shortcut in my vim configuration for a very long time and I use it frequently:

    nmap <F11> :if exists("syntax_on") \| syntax off \| else \| syntax enable \| endif \|<newline><C-g>
Similarly, there should be actual different flavours of highlighting for different tasks. I have configured a very light highlighting which highlights mostly control flow words (if, while, for, return etc) and maybe strings. It's much better than the colorful default or syntax off for many situations. On other occasions it might be useful to highlight all variable declarations, etc.

I have come to think that it's the same with programming languages: Different languages require you to type different things explicitly. Sometimes that's beneficial but often it hurts. For example, typing a function signature is much more convenient in python (just variable names), but when debugging the explicitness of a more rigid type system often helps finding bugs. Similarly typing "const" or the precise type of integer is really annoying in many situations. It's visually distracting and shifts the focus on alignment or ordering of statements, instead of the problem to be solved. On the other hand, sometimes these things are just important. It would be very nice to have a programming environment where these details can be hidden most of the time and only turned on when really needed.


I like to highlight just the places where you are defining new variables/functions/types so that the definition is easy to spot. What is the point of highlighting keywords? I suspect that highlighting engines do it simply because it's easy to do, not because it's useful.

It looks like this: http://david.rothlis.net/code_presentation/distracting_synta...


To me, all three look bad.

Eclipse - no colors for different things, hard to find what I'm looking for (if I compare to the Emacs example, if I was looking at this code trying to figure out what members this class has I'd be looking for brown and finding it much more quickly)

Emacs - terrible color scheme, both the brown and the green are too bright, not enough contrast to read.

Proposed - all the bold text hurts my eyes and distracts me from everything else.

In my crazy theme almost every "thing" has its own color, and it is very easy to find what I want by looking for the right "thing" or combination of things. As an example for where highlighting keywords would help (which is what you mentioned in your post), if I'm looking for "that for loop that does the main logic" I'd look for the place with the small blue blob on the left and a long bright blob to the right (if it was an "if" likely both blobs would be smaller ;)).


That code is pretty unreadable to begin with, don't think any highlighting or not can save it. But I prefer the Eclipse one, it lets you quickly find the various blocks (public, protected etc.) when skimming through. The proposed scheme is one giant blob.


One of the points of syntax highlighting is to create visual patterns you can recognize. Highlighting keywords may help with this. Have you tried disabling keywords highlighting and seeing what difference it makes in reading your code?


On an average day, I use visual studio for 4 languages. There's C#, HTML, JS, and some old VB.net depending on how old the code I'm working with is. Many times the same fix/feature will touch all of them. That's just on the .net stuff. Having the same general colorization scheme in place is probably all that makes skimming through code possible for me.

I remember feeling like the game changed when I went from grey and yellow on black to grey and holy crap other colors for other things on blue from turbo pascal 3 to 7. You can't take it back from me now. I've had my syntax highlighted for 2/3's of my life now, I'm not giving it back.


Yes, let's use roman numerals too lest we calculate too efficiently and be able to express more complex calculations more easily.


You mixed it up.

Syntax highlighting is like doing arithmetic using colored rods: https://groups.google.com/forum/#!msg/golang-nuts/hJHCAaiL0s...

Roman numerals is object-oriented design: https://groups.google.com/d/msg/comp.os.plan9/VUUznNK2t4Q/Ff...


This seems like old-is-new waxing, reaching for some reason the old way is better.

> Initially, turning off syntax highlighting felt weird. I couldn’t skip through the source that fast anymore and it became harder to read.

It does, that's the point of syntax highlighting. This isn't a good thing(tm).

> Even though this appeared to be an impairment I found it to be the strongest argument for making the switch. By forcing me to read the code more carefully, it made me understand it better

I tried not highlighting a bunch of times, it's called switching from my IDE to vi for whatever reason. It's not better for me.


You know that vim can syntax-highlight too, right?


Let's not use headlights anymore too... This will force the us to drive more carefully and reduce speed to avoid a potential disaster.


"The removal of road markings is to be celebrated. We are safer without them" - https://www.theguardian.com/commentisfree/2016/feb/04/remova...


I think syntax highlighting probably evolved before editors and IDEs could flag coding mistakes. A lot of the rationale for it no longer applies, e.g. coloring strings a certain way so if you forgot the terminating quotation mark, the rest of the file would change to that color and you'd know you screwed up.

I haven't used syntax highlighting for years. My IDE highlights mistakes and compiler errors, and everything else is black. It's actually a lot easier on my eyes, and the errors stand out a lot more because they are the only colored parts of the text. I only use highlighting these days to separate tags from content in markup languages like XML and HTML, where I still find it helpful.

This is all personal preference anyway, and it doesn't matter very much. But I do encourage people to try going without syntax highlighting for a few days. You may find that you didn't really need it, or that it was compensating for sloppy coding, and you may not want to switch it back on at the end of the experiment.


Even better - we should ditch color monitors altogether. You know, to be edgy and different.


My first thought was that if we close our eyes while programming, that will force us to really understand the code we write...

As someone put it, it feels like "broscience".


Sure, also let's chuck scrollback in our terminals. What's done is in the past, people.


A shiver actually ran up my spine...


I would totally code on an e-ink screen if it was larger than a Kindle.


Turning syntax coloring off was the best decision in my career. I have never looked back.


I wouldn't go as far as to say it was my best decision in my career, however it was an important one. I've noticed how I've gone from "click-friendly" GUI's and window managers like Gnome/KDE to Fluxbox, turned syntax highlighting off and at the same time increased my productivity/effectiveness. At first I missed the "fanciness", the new felt boring and pale, however as time passed it made me realize that I'm now focusing on the important things and I'm in control. So yes okay, it's one of my best decisions.


Writing programs all on a single line was the best decision of my career! The enlightenment writing everything on a single line imparted to me was nothing short of an epiphany...


It has definitely been a big improvement to my working life.


You cannot be serious.


I worked for years with SimpleText/TextEdit on the Mac (Classic/OS X) and Pico on the server.

I felt syntax highlighting was a gimmick that distracted me from my Monaco 10 with no anti-alias perfection. If I needed to do some repetitive editing beyond a simple find/replace, I'd write a small shell script. I was kind of proud of my minimalism. You can do a lot with native Carbon/Cocoa key bindings alone. Life was good.

Then someday I saw a video of someone doing crazy work in Vim. Flying. I had to learn that. I forced my self to use Vim exclusively for one job, from beginning to end. I kept watching similar videos to get over the nightmarish frustration that is anyone's first week or so in Vim. But after that, I was completly hooked.

However, I still have warm feelings when I open some code in TextEdit. Black, 10px Monaco text over a 90 by 30 white background. Ah.


This experiment applies to textbooks as well.

I looked over an old edition of Halliday+Resnick once, a well thought of lower division physics book. The text was substantially the same but it was black and white. This meant no syntax highlighting and also no glossy paper. The result was a LOT easier to read.

Glossy paper is a designery thing to do for deeper blacks but it's less readable. Indeed that's why actual designers like matte finish MBPs, because you don't want to read with a 20% opacity of yourself staring at you.


Ok, this thing with young developers going into grandfather-mode is starting to get old.

Acknowledge that it's a hipster thing to use vi and fixed gear bikes, and carry on with your life.


Coming from an age before syntax highlighting was a thing, I would hate for us to go back to it. I first saw it in Turbo C and it was amazing. This is another tool that we can use to give us better code quality.

However, some folks is pushing the syntax highlighting into realms of an art piece. I had a coworker that would using bold, italics, different font sizes, as well as colours.


I totally agree with this, and use `:syntax off`, but comments really mess with visual clarity. For dimmed comments, I sometimes switch to nofrils.

https://www.robertmelton.com/2016/04/10/syntax-highlighting-...


OP here

Great addition. For me this is a use case for conditional highlighting. What I do in my code additionally is to avoid block comments. So you can differentiate them better from your code.


Comments are the most important part of code. They should not be dimmed. If anything, they should be the only thing that is highlighted.


My highlighting scheme is to very slightly dim comments, because they tend to be more dense than code. For example: http://imgur.com/a/bxfBO


I think that this is dependent on what you are trying to do. If you want to understand what a program does than this is the way to go. If you want to program than you don't necessarily need the comments to be that visible.


I'm arguing that dimming them makes them easier to see. Code and comments are interspersed, and are each harder to see when they're the same color.


I use a slightly more intense background color on comments to make them stand out while still being readable enough.



I don't turn syntax off, but I hate rainbow in my IDE. I usually use bold for keywords, different colors for comments and string literals, underscore for class members (for Java). Basically that's all. I don't need any other highlighting, it's just a noise for me which makes it harder to read the code.


What I don't understand is that people want to highlight keywords. Bold is a very strong highlight compared to coloring it. However, keywords (if, while, return) can probably be guessed from the indentation alone. There is little need to guide my focus to them even more.


Interesting, for me it is the other way around. I use syntax highlighting (but mostly go with Vim's shipped defaults) and like the keyword highlighting the most.

E.g. looking at Python code, it highlights 'def', 'if', 'else', 'elif', 'for', 'while', etc. in orange, function identifiers in cyanish and literals (integer, float, strings) redish (on terminal with blackish background).

If I look at code, it helps me to find the beginning of a function and the parts where logic branches (conditions, loops, etc.) start. Some time ago I wrote code without highlighting and although it is obviously possible I found it harder (i.e. it took me more time) to navigate for my eyes. Maybe just using bold or italic would be enough, though.

However thinking about it, it might be a nice experiment to highlight identifiers with a unique color (or at least highlight all occurrences of an identifier below the cursor - I think Eclipse does something like that).


It allows to quickly understand general structure of the code. Indentation helps too, but it's not enough to quickly distinguish between "for" and "if", for example. Or may be I just got used to it.


It probably goes well with typing on one of these horrible new Macbook keyboards - it makes you think twice before pressing each key, thus making your code even more thought-out and succinct.

As one of those programmers who were long ago forced to use no syntax highlighting (because monitors were monochrome), I say no thanks.


I think he may have a point, but I think there's a minimal highlighting configuration that is helpful, yet not obnoxious: one where comments and constants are highlighted in their colors.

Comments are pretty much universally "skimmable" if what you want to get at is the code, and also completely unrelated to actual code (other than describing it), so I think they deserve their own color and that it is helpful. Also, conversely comments in their own color stand out from the code so that if you're looking for descriptions, they are easier to find.

Colors also being useful for constant values (strings and numeric ones alike) because at least I really want something hard coded to stand out. Sometimes it should be hard coded, sometimes it shouldn't, but pretty much always, what the hard coded content _is_, is of interest.


I don't agree with the idea whatsoever, but I really like the minimalist design of the authors website.


I do use syntax highlighting, but only with two additional subtle colors (one for literals, another for language keywords). Many editors come with themes resembling a decorated Christmas tree.


I'd argue that you could learn to read code carefully, understand what it's doing, and write good code without losing the convenience of syntax highlighting.

Unless the color scheme you were using really was so garish that it hindered your ability to improve your skills as a software engineer, in which case you could probably find a more subtle color scheme that would give you the same benefits as turning it off did. I've heard great things about the solarized color schemes. I use wombat myself.


Not sure about all the benefits and whatnot but I've learned to like 'syntax almost off' better. I do want to differentiate between comments though. And vim adds some of it's own colors to stuff like the linenumbers that I dislike.

So I use this. https://github.com/Kareeeeem/vim-walou

There's more stuff like it but I wanted to pick my own gray values and dislike pure white on pure black.


The Acme/Plan9 folk were bullish on coding without syntax highlighting (and with proportional fonts). I spent a while trying to use Acme a couple of years back and agree that it's not essential, but I switch programming languages so often these days (Python/Go/Clojure plus the occasional Java/C#) that I need it to remind myself of what goes where in each language.

But I can see the benefit of forcing you to make your code more readable in general.


I only color comments and strings.


Same. Works well for me e.g. http://i.imgur.com/RMrslmu.png


Comments and literals (numbers, strings, NULL, etc) here. http://imgur.com/a/kRbhG

I tried no-syntax-highlighting for a while, but found that a little bit is nice.


My solution for half a year now, after years of a bajillion themes, it's hard to go back, using a light theme with dark text works to an extent but I code mostly at night so I need a dark theme in general. Just use about 2 shades of grey and one other soft color. https://i.imgur.com/FHALH2G.png -- or search for Phoenix theme


In my team, an old geek man also have told me about `syntax off`. I also have tried a couple of times. But it makes my eyes hurt cause of looking carefully at every word, tokens. Another thing I consider to build my workspace is 'attractive'. Code with proper color highlight make it sexy to work with.


syntax off, proportional width, (https://twitter.com/rob_pike/status/567476552187641856), all code right aligned, ZWS for tabs


- Hey guys we wrote gofmt so all code looks the same.

- Great! Now we can finally get things done and stop bikeshedding!

- Now about that syntax highlighting of yours...


Proportional fonts + elastic tab stops [0]. I would love to have this working. Unfortunately, if you really depend on elastic tab stops you break the formatting for everybody who does not use it.

[0] http://nickgravgaard.com/elastic-tabstops/


I have the feeling most of this isn't a direct problem of syntax highlighting.

Most people simply highlight dumb stuff in their code.

For example, comments often have a bad contrast and stuff like brackets, curly braces or parathesis have high contrast.


Is there any example for this so-called conditional highlighting that we could take a look at ?


I thought broscience was supposed to stay in the gyms.


I think a large part of the issue with syntax highlighting is that our "standard" for syntax highlighting is rather dumb. A few thoughts:

- Who the hell would write prose by making all the verbs blue, the nouns red, and the adverbs green (or something to that effect). That's what we do for code. Something togglable a-la iA Writer might make sense, though. At the same time, I can sort of understand, though, because we're almost always in "edit" mode for code, very rarely in pure "write".

- I find having lint-errors highlighted provides a similar nudge to the "squiggly-red underline spellcheck".

- Our editors aren't configurable enough with regards to typography. I like to use subtle weight changes, highlighting "headings" and whatnot, and very few tools seem to make that change available.

- Semantic highlighting seems super interesting, but I haven't found a tool that I like yet.

One project I'd love to see is to get a bunch of folks together to do some proper layout-by-hand on code -- Given 100% control over typography, how would you format it to maximize readability, minimize distraction, highlight relevant contextual knowledge, etc? And then work to push tools in a direction that they support configuration to allow for said tasks.


> Who the hell would write prose by making all the verbs blue, the nouns red, and the adverbs green (or something to that effect).

Slightly off topic, but I think doing this could actually be useful for learning languages, especially highly inflected ones (if you extend the color coding to account for gender, case, etc.).


The farm was used to produce produce.

He could lead if he would get the lead out.

A bass was painted on the head of a bass drum.

That that that that boy said is not that that that that boy said.

Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.


That's what I remember doing in primary school when we were learning french grammar, and later with ESL. Is this not a common teaching tool in other languages/school systems ?


Speakers use inflection to emphasize the important things in the message. In a single method, there might be a few lines of assignments and setup, a few lines to actually do what needs to be done, and then some formatting of a return value in the correct structure.

Maybe what we want to do is emphasize the few lines that matter the most. Right now, we try to break the methods down into smaller and smaller pieces, resulting in the “In Smalltalk, everything happens somewhere else” syndrome.


I'm not sure I entirely agree with you on your first point. Writing isn't like code in that code is like a complete system of logic. I think having ways to show how that logic is organized, using positioning (whitespace) and coloring of logical operators is a pretty useful addition, whereas highlighting parts of speech (which don't express a logical structure) isn't that useful.


Yes, nice idea. For example, it might be helpful to have different colors for local variables, global variables and fields. If you accidentally shadow a variable, you might notice this way.

Likewise, highlight macros in C and make them different to variables/functions.


IntelliJ & MATLAB both change highlighting to indicate variable scoping etc, so it's neither unseen nor impossible, just uncommon in simpler editors.


More advanced tokenizers are able to emit different tokens for those scopes, but not all syntax highlighters differentiate between them. The online Textmate theme editor is a good place to examine what's availabe because many text editors are able to import .tmThemes or use them directly (Sublime, VS Code).

You can see here that the Monokai theme supports about 20 tokens and doesn't differentiate much between scopes: https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai

Personally, I prefer highlighters that do something to highlight variables differently, like this variant of Monokai (ie around line 45 for the JS example): https://tmtheme-editor.herokuapp.com/#!/editor/theme/Monokai...


EDIT: Actually, I think I misunderstood what you meant.

What you are describing sounds like regular syntax highlighting to me. This is my current theme: http://imgur.com/a/cQbWL You can see the level of customization available fits with what you described.

And it has really helped many times in the past, preventing all sorts of silly mistakes that could have been hell to debug. Like shadowing a variable :)



From reading the README, it just cycles through colors. The colors are random, not semantic, so the name seems to be misleading?


Haven't tried it yet, just bookmarked it. So I can't review it.


There is a lot of things we can do with highlighting, but that is not one that we should. An online linting tool should tell you that a variable is shadowing another (and I personally believe that it should not be possible at all). If you make a syntax highlighter that can color differently based on scope, you're only one stop away from a tool that can warn you about shadowing anyway.


Many IDEs do that. For C++ i use Qt Creator which differentiates all of that and more (virtual functions, globals, primitive vs complex types etc)


> One project I'd love to see is to get a bunch of folks together to do some proper layout-by-hand on code -- Given 100% control over typography, how would you format it to maximize readability, minimize distraction, highlight relevant contextual knowledge, etc? And then work to push tools in a direction that they support configuration to allow for said tasks.

I've had a similar thought for several years now. Want to hash out some ideas? You can contact at my site wanderingstan.com or on twitter @wanderingstan.


> Given 100% control over typography, how would you format [code] to maximize readability

There was a book on this, whose title I'm blanking on. Anyone remember? Color wasn't an element, since it was an older book focusing on printing on paper.


Kinda rings a bell for me, although not from a book, but some LaTeX manual. Maybe this helps: http://tug.ctan.org/macros/latex/contrib/algorithm2e/doc/alg...


That wasn't it, though that looks relevant for anyone thinking of working on this problem. Thanks for the pointer.


Bjarne Stroustrup's C++ book used a proportional font with tabular spacing.


So did the book I was thinking of, but it tried more fancier stuff too and iirc reported on some experiments in code reading.


Is disabling syntax highlighting the new standing desk?


I like to take advantage of my tooling to make my life easier. Writing good code is difficult enough without imposing additional constraints upon yourself to make it more challenging.


No, no, no.




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

Search: