Syntax highlighter is wrong (2014)
jameshfisher.com
jameshfisher.com
I don’t need help with reading comments. I need help with reading code. Highlighting comments distracts me from what I need to focus on to read. The idea that comments are bad, is also one I disagree with.
WRT to git diff, I intuitively understood green is added. No one had to tell me. The two “better” diff examples would cause me to misunderstand or not understand intent.
This guy seems like he should just customize his own syntax highlighting and diffing tools and be done with it.
Of course, comments also often contain the hidden assumptions or limitations of the algorithm that were too expensive to check. Often the comments actually do contain the bug you're looking for.
I suggest you give it a shot. I didn't expect it to make as much of a difference as it ended up doing.
Couldn't be more wrong on this one.
The very first "real" development environment I ever used[1] was absolutely miserable, except for two things: the comments were bright neon green, and the spellchecker was enabled (at least in my computer lab). I haven't written Java in over a decade, but I still configure each of my editors with that same bright green color for comments and with spellchecking, and I think both have made me a more diligent programmer.
If I do have something REALLYIMPORTANT (which is exceptionally rare), I plaster it all over so that it's practically not missable (esp. in code review). Sure, highlighting _that_ comment might help a bit during development, but I really don't think that use case is worth highlighting _all_ code in that case. But it could be a 'nice-to-have' for syntax highlighters.
That little bit of extra information, which only takes a few seconds to type, can save a lot of people a lot of time afterwards.
I do this, and add any addition "why" or other needed detail indented under the first summary commented line.
Making the comment large is good enough for that. But a really different tag may help here.
The comment is AFTER the code that it is commenting on. I can't remember seeing this before. Only before or at most at the end of the line.
Is that custom in any programming language community?
Not so clear with the new colors.
Maybe the author shouldn't think in bad and good but red = negative = minus and green = positive = plus.
I wonder in which color scheme he grasps the information faster.
IMHO it's the same reason editors offer folding functionality for code blocks. You get a big picture, then drill down to it, eliminating some clutter. For example, take Go's infamous `if err != nil { return err }`. I don't need to know every single one of them in a piece of code to get the big picture, so them being folded is good. Then upon further examination, I can expand them to see whether any special error handling is done at some place and why.
For diffing colors, that's why I prefer a good side-by-side viewer with syntax highlighting. The default unified diff output is pretty useless when more than 2 consecutive lines changed. That is something that GitLab and others get right: side by side, changes to a line highlighted to tell "hey, only this word in the line changed, but it still count as the whole line being replaced".
Meh, I think javadoc is somewhat antiquated but otherwise an ok markup language for documentation. I do like that newer languages seem to have switched to a version of markdown for documentation.
Please don’t argue about either of those in reply to this comment. Both objectively have more of an impact on committed code, and that’s my only point. My functions are orange and my variables are blue. I don’t care how yours are distinguished, if they are, unless I’m reading your shared screen. It has less of an impact on my comprehension than minuscule font sizes.
That's the same reason people use them on numbers too.
if your boss looks at a red diff and thinks it's bad, that's a you and him problem, while the primary purpose for color syntax continues to be making it easier to parse for people who know what they're looking at
It may add value, so may be figuratively a very positive change. But not literally.
A red apple is not inherently bad nor is a green apple inherently good. A person might enjoy one versus the other to eat, but if you just ask someone to identify attributes of an apple, the color likely won't prompt statements about the good/bad nature of the apple, and instead would decide the apple's use based on your needs. This can be done with just about any color association and at its core, people will include the context when considering the associations. Red machines are better because they're faster, after all, even if you're not making a WH40k joke.
I think the author of the article overstates the implicitness of the associations they make with red/green and propose that everyone has such strong associations. When I read a diff, the color doesn't matter, I just need to know what it indicates. I set my terminal colors and syntax highlight colors not to indicate some specific judgement on the colors, but because I want different things to stand out so when I am scanning.
Bright red stands out well in general, so it's useful for errors so I catch it when scrolling, which typically are what I'm interested in if I'm checking a log. Based on my primary interest, I pick the other colors that are complimentary to red or opposing to help quickly categorize. With diffs, I am interested in what got the axe typically, because first I want to see "what did we have before?"; it's very difficult to judge if what was added is an improvement without knowing the context of what was replaced, so for me, it makes sense to focus on what was originally there, then see what was changed. This is naturally _my_ association and interpretation, and frankly it could work with any scheme assuming the colors were different enough.
I think at the end of the day it's insane to expect the people that who were unable to express themselves clear in formal code will somehow gain the ability to express themselves clearly in informal comments.
Although now that I think about it I could make number literals coloured the same as the string literals, but I don’t really have any trouble distinguishing numbers from code (whereas sometimes strings can look like code).
Other that that, at least for me, a little syntax highlighting goes a long way, mostly I don't use it at all.
I can’t think of a UX that would work well for generally colouring identifiers distinctly though.
One nice feature that does exist is selecting an identifier and highlighting other instances of that identifier (semantically, not just by string matching). This makes actively reading code a lot easier. It would be interesting to see this extended to allow multiple selections.
I've seen that done for read-only code readers, Backbone.js' annotated source code [1] comes to mind, but I wonder how that would work for the editing portion of an editor.
[1] https://backbonejs.org/docs/backbone.html
> Or perhaps one that toggles their visibility?
Vim has code folding ability, which you can set up to apply to comments. I'm sure this isn't exclusive to Vim though.