The color red is often associated with bad; needs to stop; wrong. Removal isn't such a big step from there, I think. The opposite probably applies to green.
Since I'm sitting here with a voltmeter next to me, I'll point out that red==positive and black==negative.
The bigger point I'd like to make is that any talk of universal connotations of colors is probably wrong unless you've really studied it carefully.
For some history on why red means stop and green means go, see Straight Dope: http://www.straightdope.com/columns/read/437/who-decided-red...
Apparently it dates back to early railroads, where red meant stop, green meant caution, and white meant go. They discovered this wasn't failsafe when the red filter fell out, the train saw a white light and crashed. So they moved to green for go.
...no? As in China, they adopted red because of its preexisting immense popularity (well, for the USSR it seems they also drew on some "revolution is red" symbolism). Your causation is running backwards.
> The colour red has always been a positive symbol in the Russian culture. The word red (Russian: красный, krasnyy) is etymologically related with the Russian word for beautiful. This can also be seen in Moscow’s Red Square and the Russian Orthodox festivity, Red Easter.
I don't buy that. Most programmers have learned that, in a diff, red = deletion and green = insertion. But I'm not sure that is "intuitive" as much as "learned behavior".
In the field of genetics-- and specifically for copy number variation (i.e., big chunks of genome deleted or inserted)-- the red/green contrast was deemed inaccessible to color-blind individuals, and so a new red/blue scheme was implemented as a consensus scheme.
red - deletion of genetic sequence
blue - insertion of genetic sequence
As per the siblings, I don't really agree that this is intuitive. What it definitely is: widespread, accepted, well-known, not confusing - pretty much the same thing.
I believe the reason for this strange color scheme is the lack of a revision control system. Back in the dark ages of programming, we didn’t use them. We edited files on disk, and that was that. In that environment, a deletion is dangerous. If you decide you want it again after you delete it, well, that’s tough.
I don't think this explanation makes any sense. What was this person from the dark ages diffing against? Presumably, something on disk (i.e. something whose contents are recoverable).
One of the main rants in this is about superfluous comments. I completely agree that comments which are superfluous should be removed. However all his examples are JavaDoc. Yes, in the code they are useless because of the variable declarations, however they are of great use in an IDE.
I was thinking the same thing. Yes, the comments might look pointless when viewing source code on GitHub but really makes life easier with an IDE and documentation generation.
Sure, take out those comments, but then his next blog post would be about the lack of decent documentation available for various projects...
And most syntax highlighters actually allow different styling on Javadoc comments than on block comments or line comments. There's no reason to treat them the same.
I disagree about insertions and deletions. The primary purpose of colors should be to communicate more information without us having to think about. Having standard color schemes is really helpful. If every service uses different insertion/deletion colors, that's just more headache for us.
Additionally, to me, red deletion doesn't mean "this was a bad action". It means "this was bad code, so we're crossing it out". Semantically, that makes total sense to me. Red is bad old code, green is new good code. Seeing a lot of red in code means the same to me as seeing a lot of red on a marked up copy of an essay (as long as it wasn't a professor who marked it up) -- I've identified a lot of improvements to make.
I don't think this should be in the application. It's a monitor or OS issue. Couldn't we just use a color calibration matrix to map all colors to the spectrum the colorblind person does see?
That's not the same. When you go from 3D to 2D you lose a dimension. Information is lost. When you map color spaces like I proposed you go from 1D to 1D, you're just compressing the data in that dimension. No information is lost (except because of the limits of numerical accuracy)
So you propose that colorblind people should make their OS turn all images, photographs and video into false color not correlating with reality because in some specific contexts color is used symbolically and it's important to distinguish between two colors? One option that might work would be a special drawing mode implemented in the OS graphics stack that did some mapping depending on what's configured in the accessibility settings; then applications could request that in the rare cases where it's important.
As a partially colorblind person (albeit easily capable of telling red from green here), while of course such a mode should not be required for programming, I wouldn't mind using it in general. The EnChroma glasses try to do this in real life, but they're expensive and only work in bright sunlight; if I can at least get the same for photos just by downloading something, it sounds interesting. (And probably already exists, so I should do some Googling.)
That's a really interesting idea. You'd want a fast toggle for it, so that you could use it primarily for browsing semantic content that uses colors, but not always for photographs or videos that represent the real world (unless those photos or videos contained such semantic content). It's not ideal, but much like assistive devices that translate vision to other nerve impulses (http://www.nei.nih.gov/news/briefs/weihenmayer.asp), it could be useful as a learned adaptation.
That said, it would also make sense for diff software in particular (as one of the most prominent software uses of red and green right next to each other for semantic purposes) to have an easily adjusted option for a different color scheme for the very common case of red/green colorblindness.
Red/Green colorblind doesn't mean we don't see red and green, it's just not as powerful. It should read Red/Green deficient. Maybe that is why it doesn't seem so bad because to a Red/Green colorblind person the colors are more subdued.
I do realize this. I also know someone that has had problems with it on github's diffs. I do think it would be better to use other colors to avoid the issue entirely.
These were also my thoughts when reading the article. I have always associated red with old and green with new. I also do not think red conveys the negative meaning the author suggests it does.
I do, however, believe the author has a very strong argument relating to code comments. I'd like to see a shift towards this style of highlighting in the future as I often find myself having to modify nearly every colour scheme I use to make comments far more prominent.
I think this may be correct. Personally I always wanted the syntax highlighter to highlight only function calls and object method calls.. ex: .Trim() would get highlighted in mystr.Trim()
It also annoys me endlessly that words like 'var' and 'def' and 'function' get the brighest highlight, i know its a variable, it has a name, and i put it there.
Aw, I was hoping article was going to be about the highlighter's grammar rather than its colors. Perhaps there exists a system other than, "colorize keywords and comments". Or maybe build color into the language itself, as done by colorForth.
I think the author is overthinking it in the second section: we're not discouraging deleting code by marking it red. We're simply denoting that it was removed, or killed off (he drew the connection of red to blood, and green to new life).
However I don't understand why diff views abandon syntax highlighting. I understand there's sometimes a challenge of breaking up highlighting that depends on syntax that spans multiple lines, but it seems like we could do better than marking entire lines bright red and green and leaving the text black. This is the biggest thing that confuses me about Github - they've left it like this for years and it's probably the most looked-at part of their site.
Yep. And it's mostly about communicating. That they choose red for removals and green for insertions is meaningless. We may argue the same nonsense about stop lights. A parked car is safe a moving one can kill. So let's replace the stop lights colors. What? Yeah. Silly argument. The colors do not matter at all. Sometimes a cigar is just a cigar.
When programmers all around the world look at the red/green in a diff they understand it, without having to search for a legend explaining the colors.
This is something that most code review tools apart from GitHub get right. For example Critic, Review Board, Phabricator and Gerrit all implement side-by-side diffs with correct syntax highlighting on each side. I don't know why the GitHub experience is so far from the state of the art.
I would imagine it's easier to do syntax highlighting on side-by-side, because you can just reuse your existing syntax highlighter. But when presenting the `-/+` style of diff, you need a custom syntax highlighter that not only can skip over the `-/+` tokens but can also handle having two separate-but-intertwined non-contiguous highlighting states (because the `-` lines will be using a different state than the `+` lines).
And then what do you do if the state ends up different when you hit the context lines again? There's no obvious choice as to how to highlight those.
Right, so the question is "why not have side-by-side diffs". The fact that syntax highlighting would work is one obvious advantage. It also means that you can read the before/after code linearly without having to mentally apply the patch. It seems like an obviously better UI for understanding the effect of changes (although of course I don't have data to back that up).
I would like to see GitHub offer the option of seeing side-by-side. It can be helpful if you have a mess of tiny -/+ hunks right next to each other. But combined is definitely the correct default.
What do you mean? First off, you're making the assumption that your highlighting library gives you results that can be trivially split per-line (e.g. no styles cross line boundaries, line boundaries are easy to find, etc). I haven't worked with web highlighting libraries so I don't know if that's true. But let's say it is. Now how do you handle the problem I called out, where the context lines are highlighted differently in both versions? You only show the context lines once in a combined diff.
about comments being washed out: in the quest of writing good source code for kids (easy for kids to read, adapt and use) I found that comments should be not only an integral part of the source, but probably not highlighted as a single block, with an uniform color. For kids and beginners, we should have a highlighter for comments that bold words between *, that put some emphasis on titles in comments, that makes function/variable names in comments jump out. Also, we could highlight inline comments (at the end of a line of code, generally frowned upon but potentially useful for beginners and kids) as yellow stickies.
And tokens in the comments that match or nearly match tokens in the code should be colored the same or even have arrows drawn between them when hovered over.
Most editors allow you to customize the syntax highlighting color scheme. It's a bit more difficult in a web editor, but is possible with some JavaScript and an extension like Greasemonkey. Then again, how often are you really using the GitHub code browser -- if it's a lot, wouldn't it be easy enough to clone the repo and explore it in the editor of your choice?
This is blatantly wrong:
"red means bad and green means good. This association is cross-cultural, probably universal, and probably as old as the hills: red as blood, green as grass. "
I completely disagree that comments should be called out in bold because they are supposed to add important information. Even in code where that is the case, they are still just metadata. Comments are there to help you understand something. Comments should never be shouting at you, drowning out the code itself. We only have so much attention to spare, and most of that attention should be focused on the actual code, not the comments.
The biggest danger of comments (especially in heavily over-commented code) is that they can be misleading. If you get over used to relying on the comments as a true indication of what the code does, it's easy to be misled. It can especially cause you to miss subtle errors in the code (like an = instead of ==, or > instead of <).
Your eye should be drawn to the code first and foremost. Hence it is most important that it is formatted neatly and really, syntax highlighting is just a good way to catch typos quickly.
Comments should be what you read second, not what you read first. I.e., I just read this bit of code and it seems a bit weird, so I'll check the comment - oh yeah, now I understand what it's doing. Most comments should be ignored most of the time.
"we have collectively decided that the comment is less important than the code" - this is simply because the comment is less important than the code. Comments are not necessarily correct and don't always accurately represent what the code does. The code however, is always 100% accurate. That's why experienced programmers rely on the code first, comments second and try to avoid commenting ideas that can be expressed equally well in the code itself.
The use of Javadoc style comments is another strawman. As much as we might wish it were not necessary, using comments to generate documentation is actually useful. Similarly, having a coding standard requiring a comment block per class/function for the docs is also useful. A standardised structure is helpful when reading lots of code, and it helps delineate long source files, even if many of those comments turn out to be redundant. Having a highligher scream about all those comments being super important isn't helping by making people write more concise comments - it's merely trying to solve a problem that doesn't exist and creating a new problem in doing so.
Sometimes I need to comment something that really is super important like the example in the OP. It turns out, there's a way to do that which doesn't even rely on having any syntax highlighting whatsoever. You just write your comment like this:
// !!!!! IMPORTANT WARNING !!!!! //
// This does something really dangerous,
// so don't change it unless you understand it...
// !!!!! BEGIN CRITICAL SECTION !!!!! //
if(foo) {
bar();
}
// !!!!! END CRITICAL SECTION !!!!! //
I write code that needs something like this maybe once every 6 months. Do I want every single comment that I write called out with equal importance? Nope. Is limiting comments to only comments of such dramatic urgency a good idea? Also no.
A related rookie mistake that I see a lot is conflating the idea that less code = less complexity. Inexperienced programmers like to cram as much logic onto one line as possible, whereas better programmers often write the same thing as one-statement-per-line with a bunch of temporary variables, whose name encapsulates what each operation is doing. Which one do you think requires several lines of comments to explain what it does, and which requires no comments whatsoever? One has less code, but both have the same complexity. Except the one with more code breaks that complexity out into smaller, less complex individual chunks which makes reasoning about the whole much, much easier.
I agree with most of the first section but there are scenarios where washed out comments are better. If I comment out a block of code while debugging, I don't want it to be bold and highlighted. Maybe highlighters should be able to differentiate between natural language and code.
To me, this is a terrible example, because it's a useless comment. The comment should explain what "x" is for, not what you're doing to it. I you have a comment about what "x" is for, which becomes more important? The assignment, or the explanation?
"x" is not always something which can be easily or fully explained in one to four words. And anything over four (short) words is typically getting too cumbersome as a variable name.
Shrug. Most of the code I have to deal with regularly is primarily commented with profoundly unhelpful, often blatantly incorrect nuggets such as this. Forever what and never why. It seems better if it just faded into a fossilized archeology that only needed to be Gandalfed in the most dire circumstance.
In my situation, making the comments "stand out so that people will make better ones or fix them" seems optimistic to the point of being naive. We may in the end be down to the old "what should be" vs "what is".
Really? The only time you need to know that removing that line will cause a segfault is if you are going to remove that line; but, if you're going to remove the line, you're surely going to check the comment above it, even if the comment doesn't jump out at you. Even an important comment is still irrelevant except when you are looking for clarification about the code it comments on; so I don't think it ever makes sense for comments to be emphasized more than the code.
One of the points made by the article is that if syntax highlighters made comments jump out at people, they wouldn't be so eager to comment unnecessarily (like in your example) since it'd start looking bad. It's a solution that fixes two problems in one go.
Having the comment bolded would be excellent! It would immediately highlight that the comment is both useless and incorrect, and should be removed. The only comments that should remain are those that you really don't want to miss.
1st world problems - some people have obviously never had to debug on a 3 inch thick printout on fan fold paper where he only highlighting was the highlight pens you used.
Rephrased: This "Your cake is poisonous" talk is tedious. Tell me about the healthier cake you've baked or STFU while I eat my cake.
What I mean is, criticizing something is useful in itself. It's not necessary to also propose a better way. Sometimes it's enough to STOP doing something, you don't have to find an alternative for it.
I thought this was going to be about the ambiguity of some languages when being parsed. Go and Perl are a good example of such a languages. Pretty disappointed with the article even forgiving that. Importance is only a matter of perspective.
Because there is only one way for it to be "correct", eh?
Seriously, to each his own. My IDEs all support customizable syntax highlighting to use whatever I want. They all ship with some default settings, but I mod them every time to support what works for me.
That's the correct answer -- whatever works best for the individual is what is "correct".
Although I like the idea of comments in a stand-out color, red and green for deletion and insertion is absolutely necessary. It's intuitive and the standard, and using other colors (ugly tones of yellow and purple) is both ugly and confusing. If I showed the red/green screen to someone, they'd intuitively know what's being deleted and not. If I showed the purple/yellow screen to someone, they'd scratch their heads.
Also, the proposal that reviewers will determine whether or not to reject a patch based on how the colors look is preposterous. Imagine the Heartbleed patch being rejected because the colors look ugly. (This is, hilariously, the example the author uses.)
Although I like the idea of comments in a stand-out color, red and green for deletion and insertion is absolutely necessary. It's intuitive and the standard, and using other colors (ugly tones of yellow and purple) is both ugly and confusing. If I showed the red/green screen to someone, they'd intuitively know what's being deleted and not. If I showed the purple/yellow screen to someone, they'd scratch their heads.
Also, the proposal that reviewers will determine whether or not to reject a patch based on how the colors look is preposterous. Imagine the Heartbleed patch being rejected because the colors look ugly. (This is, hilariously, the example the author uses.)
This will sound weird, but I actually turn off the syntax highlighter most of the time. I usually use a black background in my terminal, and often the syntax highlighter (or even directory colours in a shell) are set to dark blue, which I have a really hard time distinguishing.
I could remap my colours, I suppose, however I used to often find myself trouble shooting at someone else's terminal. Since then I just found it easier to have it turned off completely.
I think the source of the problem with comments is that we try to make them serve two purposes:
1) Give the code clarity
2) Be the source of documentation
These goals aren't easily reconciled, too many comments reduce clarity whilst increasing the likelihood that they are inaccurate and not maintained.
Documentation generated from comments seldom explains how to use the APIs that a library or program exposes. Usually resulting in the addition of more comments, further reducing code clarity.
The real problem with comments is that too few of us write useful documentation.
I can't remember who said that the best thing a programmer can do is to learn to write.
Our job isn't just to write code, it's also to make sure the code is used... meaning we need to learn how to sell our code to people who will maintain and implement things against our interfaces. We need to sell to other devs, by documenting better and explaining how to use our code. Only then can we reduce the in-line comments that reduce readability of code.
131 comments
[ 5.7 ms ] story [ 204 ms ] threadThe bigger point I'd like to make is that any talk of universal connotations of colors is probably wrong unless you've really studied it carefully.
For some history on why red means stop and green means go, see Straight Dope: http://www.straightdope.com/columns/read/437/who-decided-red... Apparently it dates back to early railroads, where red meant stop, green meant caution, and white meant go. They discovered this wasn't failsafe when the red filter fell out, the train saw a white light and crashed. So they moved to green for go.
From http://en.wikipedia.org/wiki/Flag_of_the_Soviet_Union :
> The colour red has always been a positive symbol in the Russian culture. The word red (Russian: красный, krasnyy) is etymologically related with the Russian word for beautiful. This can also be seen in Moscow’s Red Square and the Russian Orthodox festivity, Red Easter.
But the whole point is that code removal shouldn't be associated with being negative and so shouldn't be coloured red.
So red text has come to mean '-'.
'-' is also 'taken away', so I can see why it's logical to have it in red.
As for green.. well - opposite.
red - deletion of genetic sequence blue - insertion of genetic sequence
1: https://www.iscaconsortium.org/index.php/the-news/95-the-mea...
I don't think this explanation makes any sense. What was this person from the dark ages diffing against? Presumably, something on disk (i.e. something whose contents are recoverable).
Sure, take out those comments, but then his next blog post would be about the lack of decent documentation available for various projects...
Additionally, to me, red deletion doesn't mean "this was a bad action". It means "this was bad code, so we're crossing it out". Semantically, that makes total sense to me. Red is bad old code, green is new good code. Seeing a lot of red in code means the same to me as seeing a lot of red on a marked up copy of an essay (as long as it wasn't a professor who marked it up) -- I've identified a lot of improvements to make.
That said, it would also make sense for diff software in particular (as one of the most prominent software uses of red and green right next to each other for semantic purposes) to have an easily adjusted option for a different color scheme for the very common case of red/green colorblindness.
I do, however, believe the author has a very strong argument relating to code comments. I'd like to see a shift towards this style of highlighting in the future as I often find myself having to modify nearly every colour scheme I use to make comments far more prominent.
It also annoys me endlessly that words like 'var' and 'def' and 'function' get the brighest highlight, i know its a variable, it has a name, and i put it there.
However I don't understand why diff views abandon syntax highlighting. I understand there's sometimes a challenge of breaking up highlighting that depends on syntax that spans multiple lines, but it seems like we could do better than marking entire lines bright red and green and leaving the text black. This is the biggest thing that confuses me about Github - they've left it like this for years and it's probably the most looked-at part of their site.
When programmers all around the world look at the red/green in a diff they understand it, without having to search for a legend explaining the colors.
And then what do you do if the state ends up different when you hit the context lines again? There's no obvious choice as to how to highlight those.
You don't have to "mentally apply" a patch, just ignore some lines of a certain color.
I'm not convinced "pick one" is a horrible choice.
http://youtu.be/z2exxj4COhU?t=16m6s
The biggest danger of comments (especially in heavily over-commented code) is that they can be misleading. If you get over used to relying on the comments as a true indication of what the code does, it's easy to be misled. It can especially cause you to miss subtle errors in the code (like an = instead of ==, or > instead of <).
Your eye should be drawn to the code first and foremost. Hence it is most important that it is formatted neatly and really, syntax highlighting is just a good way to catch typos quickly.
Comments should be what you read second, not what you read first. I.e., I just read this bit of code and it seems a bit weird, so I'll check the comment - oh yeah, now I understand what it's doing. Most comments should be ignored most of the time.
"we have collectively decided that the comment is less important than the code" - this is simply because the comment is less important than the code. Comments are not necessarily correct and don't always accurately represent what the code does. The code however, is always 100% accurate. That's why experienced programmers rely on the code first, comments second and try to avoid commenting ideas that can be expressed equally well in the code itself.
The use of Javadoc style comments is another strawman. As much as we might wish it were not necessary, using comments to generate documentation is actually useful. Similarly, having a coding standard requiring a comment block per class/function for the docs is also useful. A standardised structure is helpful when reading lots of code, and it helps delineate long source files, even if many of those comments turn out to be redundant. Having a highligher scream about all those comments being super important isn't helping by making people write more concise comments - it's merely trying to solve a problem that doesn't exist and creating a new problem in doing so.
Sometimes I need to comment something that really is super important like the example in the OP. It turns out, there's a way to do that which doesn't even rely on having any syntax highlighting whatsoever. You just write your comment like this:
I write code that needs something like this maybe once every 6 months. Do I want every single comment that I write called out with equal importance? Nope. Is limiting comments to only comments of such dramatic urgency a good idea? Also no.A related rookie mistake that I see a lot is conflating the idea that less code = less complexity. Inexperienced programmers like to cram as much logic onto one line as possible, whereas better programmers often write the same thing as one-statement-per-line with a bunch of temporary variables, whose name encapsulates what each operation is doing. Which one do you think requires several lines of comments to explain what it does, and which requires no comments whatsoever? One has less code, but both have the same complexity. Except the one with more code breaks that complexity out into smaller, less complex individual chunks which makes reasoning about the whole much, much easier.
In my situation, making the comments "stand out so that people will make better ones or fix them" seems optimistic to the point of being naive. We may in the end be down to the old "what should be" vs "what is".
Really? The only time you need to know that removing that line will cause a segfault is if you are going to remove that line; but, if you're going to remove the line, you're surely going to check the comment above it, even if the comment doesn't jump out at you. Even an important comment is still irrelevant except when you are looking for clarification about the code it comments on; so I don't think it ever makes sense for comments to be emphasized more than the code.
What I mean is, criticizing something is useful in itself. It's not necessary to also propose a better way. Sometimes it's enough to STOP doing something, you don't have to find an alternative for it.
Seriously, to each his own. My IDEs all support customizable syntax highlighting to use whatever I want. They all ship with some default settings, but I mod them every time to support what works for me.
That's the correct answer -- whatever works best for the individual is what is "correct".
Also, the proposal that reviewers will determine whether or not to reject a patch based on how the colors look is preposterous. Imagine the Heartbleed patch being rejected because the colors look ugly. (This is, hilariously, the example the author uses.)
Also, the proposal that reviewers will determine whether or not to reject a patch based on how the colors look is preposterous. Imagine the Heartbleed patch being rejected because the colors look ugly. (This is, hilariously, the example the author uses.)
I could remap my colours, I suppose, however I used to often find myself trouble shooting at someone else's terminal. Since then I just found it easier to have it turned off completely.
1) Give the code clarity
2) Be the source of documentation
These goals aren't easily reconciled, too many comments reduce clarity whilst increasing the likelihood that they are inaccurate and not maintained.
Documentation generated from comments seldom explains how to use the APIs that a library or program exposes. Usually resulting in the addition of more comments, further reducing code clarity.
The real problem with comments is that too few of us write useful documentation.
I can't remember who said that the best thing a programmer can do is to learn to write.
Our job isn't just to write code, it's also to make sure the code is used... meaning we need to learn how to sell our code to people who will maintain and implement things against our interfaces. We need to sell to other devs, by documenting better and explaining how to use our code. Only then can we reduce the in-line comments that reduce readability of code.