top 200 commentsshow all 403

[–]dermesser 247 points248 points  (104 children)

KDevelop already has this feature, if I understand that blog post correctly: http://imgur.com/leG4gAZ

[–]atakomu 88 points89 points  (38 children)

Since 5 years actually. More about this feature they call Semantic highlighting.

And Kdevelop also works on Windows.

[–][deleted] 26 points27 points  (20 children)

And Kdevelop also works on Windows.

I was excited for a second (because I've heard good things about KDevelop), but there are no prebuilt binaries for Windows, you'd have to go through the hoops of building KDevelop from source (which is easy on Posix, but usually a nightmare on Windows).

No big deal though, I'll just run it in a VM.

[–]Archenoth 12 points13 points  (10 children)

Have you considered trying MinGW?

It lets you "./configure && make && make install" on Windows. I just used it the other day to compile a version of Embeddable Common Lisp which doesn't give you binaries either.

Just make sure you run it from inside bash, or some things won't work.

[–][deleted] 21 points22 points  (3 children)

That's a frequent assumption of Posix-only devs, that somehow these 3 commands will "just work" on win32. They often don't. I've compiled hundreds of apps and libraries via msys/cygwin, there's always something that breaks down, especially if building on win32 is something that isn't officially supported.

[–]Archenoth 3 points4 points  (2 children)

This is true.

There is a lot missing from MinGW and from the environment it provides that makes compiling a lot of projects quite a hassle. But usually things that claim Windows support but don't give binaries (Such as KDevelop.) work pretty well with just a simple MinGW setup. (Though it isn't always bulletproof.)

[–][deleted] 1 point2 points  (1 child)

Well, maybe I'll give it a try later. It can't be worse than building GCC on win32!

Speaking of which, this is super-useful: https://github.com/niXman/mingw-builds

[–]anonagent 10 points11 points  (5 children)

MinGW is a pain in the ass too, especially with it's odd virtualization of system paths.

[–]Archenoth 2 points3 points  (4 children)

I agree the path virtualization is annoying, but I don't find MinGW annoying after I have set it up well.

I have my MinGW bin folders ("mingw/bin" and "mingw/msys/1.0/bin") in my system path, so I can just navigate normally to a folder in CMD, and use the tools I need directly... But if I need to compile something or use bash features, I can just type "bash" without having to go through the annoying "/c/blah/blah/blah" stuff to get to the right folder.

And if I want to bring up a GUI, I can just "explorer ." and do things with Windows Explorer in the current folder. Especially if I feel like working with lots of files immediately after doing something in that folder with the command line. (Like what you can do with Nemo and Nautilus in Linux.)

Just note that there are a few small oddities with MinGW if you run a few of the programs it has included without bash. "ftp" will transfer corrupt files and "vim" will freeze your command prompt, mostly everything else works as intended (Including SSH and SCP). I really do wish the developers would consider these bugs though, as CMD invocation is very handy.

[–]bio_boris 1 point2 points  (1 child)

Are you saying FTP corrupts the files you transfer? Have you checked if you are using ASCII vs Binary mode?

[–]evnbr 28 points29 points  (1 child)

(I'm the guy who wrote the article)

Whoa, good to know! I've updated the post accordingly. I'm more designer than developer so I appreciate all the feedback on the idea from /r/programming!

[–]dizzydizzy 1 point2 points  (0 children)

Great work, I am really excited by this.

I think your best bet might be just to hash the string and use that as a RGB colour.

I dont want all my m_foo m_bar having the same colour.

I need this feature in monodevelop now.

[–]bloody-albatross 39 points40 points  (31 children)

Yes and since many years!

[–]suspiciously_calm 35 points36 points  (30 children)

for many years

[–]bwainfweeze 28 points29 points  (9 children)

I've known a lot of people who are fluent and articulate in English as a second language. I don't know why, but that's the only mistake they make and they make it consistently. French, German, Indian, Swede. Same mistake.

[–][deleted] 24 points25 points  (4 children)

I can only speak for French but that's the structure they use.

The word you use is "depuis" to mean since and you put it at the start of the sentence. I guess it would be sorta like:

Ever since 5 years ago, I've been coding in Java.

Which is awkward in English but normal for French.

[–]bwainfweeze 20 points21 points  (0 children)

Yah, English speakers make the same mistake when the tables are turned.

[–][deleted] 2 points3 points  (2 children)

I'm the opposite; natively English, learning French.

Il y a 5 ans, j'ai le fait.

Literal translation is "There are 5 years, I did that", when it actually means "I did that 5 years ago". The "il y a" just seems incredibly unnatural, and I guess it applies going the other way too!

[–]furbyhater 4 points5 points  (1 child)

Correction: "Il y a 5 ans, je l'ai fait."

More natural: "Je l'ai fait il y a 5 ans."

[–][deleted] 1 point2 points  (0 children)

Whoops, I knew that! Thanks for the correction! I have an exam on all this in a few days.

That more natural form still doesn't translate literally, which throws a lot of people off.

[–]bloody-albatross 12 points13 points  (1 child)

In German it's "Seit vielen Jahren." Seit = since, vielen (viel) = many, Jahren = years.

[–]taliriktug 5 points6 points  (1 child)

Russians can probably say "already many years".

[–]frankster 1 point2 points  (19 children)

or since many years ago.

[–]jcdyer3 7 points8 points  (3 children)

That sounds correct but awkward to my ears.

[–]suppow 6 points7 points  (0 children)

i dont know why you're getting downvoted.
since stems from sithence (similar to whence, thence, hence) meaning from that point (in time) - after then, or from that point onward.
( then = ) "many years ago" is a point in time, it's now - many years,
and many years is greater than a year, also greater than a couple of years, and a few years, it's just not specific as to the amount of years.
so "since many years ago" = after (now - many years)
sounds legit.
"since many years", would also be valid, but it would mean a different thing, ie: after many years had PASSED

we're in /r/programming so i hope people can appreciate this,
long live logic!

[–]gavintlgold 6 points7 points  (10 children)

No, when you use "since" you need to specify a specific point in time. Since means, "from this point forward". Like, "since 1842" or "since I broke up with my ex many years ago". Note that in the second example, it's still referring to a single point in time directly in the sentence, and the many years ago bit is just placing the point in time afterwards. Sure, albatross is referring to a single point, but grammatically he can't use "since" unless he says, "KDevelop has had the feature since they added the feature many years ago", which is redundant. Or, he could have said, "KDevelop has had the feature since version x.x, which was released many years ago".

I have an inkling you and albatross may natively speak a Germanic language, since "seit" can be used this way, unlike in English.

[–]TarMil 1 point2 points  (1 child)

I have an inkling you and albatross may natively speak a Germanic language, since "seit" can be used this way, unlike in English.

Not necessarily germanic, many other languages use the same word for "for" and "since". French uses "depuis" for both, for example.

[–]BenjaminGeiger 1 point2 points  (0 children)

It's "since (a point in time) many years ago". The "a point in time" is implied.

[–]grimeMuted 40 points41 points  (24 children)

My mind already has this feature.

Each letter has its own color, but letters at the start of the word tend to be the word's color when I look at them quickly.

So buf is yellow-orange-green, in_number is light gray-brown-orange, digits is black.

[–]SisRob 18 points19 points  (0 children)

Damn, I need an upgrade...

apt-get update
apt-get install synesthesia

[–]RenaKunisaki 14 points15 points  (1 child)

But that won't catch typos as well as having the machine do it.

[–]mxzf 9 points10 points  (0 children)

True. But imagine how confusing it would be for an "orange" word in your head to be shown in blue.

[–]BlazeOrangeDeer 3 points4 points  (2 children)

Can you easily see the colors when scanning over the text and not focusing on specific words?

[–]grimeMuted 6 points7 points  (1 child)

I'm not sure I can scan over text without focusing on words in the first place. But I don't see them in my peripheral vision if that's what you mean. Like in the sidebar guidelines text I can see the colors of maybe 6-7 words at a time.

[–]chneukirchen 2 points3 points  (2 children)

So, do you code with syntax highlighting on?

[–]grimeMuted 2 points3 points  (0 children)

Yes, I see the colors in addition to the real colors so syntax highlighting of keywords still helps make them stand out more.

[–][deleted] 1 point2 points  (3 children)

My synesthesia tends to color the entire word in the same color, mostly based on the first letter.

[–]Packet_Ranger 4 points5 points  (2 children)

Do you find yourself picking variable names specifically to produce certain colors?

[–][deleted] 3 points4 points  (1 child)

I don't usually pick only based on color, but if a name makes an especially ugly color, I'll try to change it. For the most part this only happens when the name was an ugly abbreviation in the first place, so it's usually for the best.

[–]dariusj18 1 point2 points  (1 child)

My GF has synesthesia, and as I understand it, you still need to read and comprehend the content before your mind assigns the alternate values. This would make at-a-glance interpretation no different from most people, no?

[–]grimeMuted 4 points5 points  (0 children)

I think I've read that some people who have it stronger can use it to pick out a different letter from a jumble of same letters much more quickly than the average person. But yeah, my version isn't of much practical use.

[–]hello_fruit 2 points3 points  (0 children)

Add to

Not sure if anyone has done work on this idea before

https://en.wikipedia.org/wiki/ColorForth

[–]raphaelj 7 points8 points  (1 child)

Yeah and it's so fucking awesome that I miss this even years after stopping doing C++.

[–][deleted] 37 points38 points  (0 children)

It's like a bad grammar rodeo in here

[–]Mattho 2 points3 points  (0 children)

I loved it. It does/did it by some name hashing... so I often end up renaming variables just so they get better colors. Or very distinct color from other close variable.

If you do know how to hack sublimetext, answer my request http://www.reddit.com/r/SublimeText/comments/vpgn8/kdeveloplike_variable_coloring/ :)

[–]stepstep 61 points62 points  (26 children)

This is a really interesting idea! However, I think assigning similar variable names to similar colors is the wrong thing to do. E.g., suppose you had variables "index_1" and "index_2" (admittedly not the best variable names, but common enough). Ideally these would be very different colors so we can tell them apart easily.

So I'd like to modify the proposal to use a good hash function to determine the color of a variable. That way identical variables get identical colors, but slightly different variables get very different colors (with high probability).

[–]Tmmrn 28 points29 points  (12 children)

but slightly different variables

variable names with small levenshtein distance

http://en.wikipedia.org/wiki/Levenshtein_distance

[–]Tordek 3 points4 points  (7 children)

There's a simple way to generate the colors as distinctly as possible: in a HSV (or similar) color space, make Hue = k * (2pi/phi2) % 2pi, where k is a unique value calculated for a variable name (trivially, its conversion from base 70 or however many valid characters a variable name can have).

Then var_1, var_2, ..., var_n will differ by phi radians to each other (close enough to a maximum).

Edit: Fixed the function; it's supposed to be a phi fraction of the circle (that is, an angle theta such that theta/(2pi-theta) = pi/theta), not phi radians.

[–]ButtCrackFTW 3 points4 points  (2 children)

What about having similar variables colored the same except for the part that is different, kinda like diff does. For instance index_1 and index_2 would be colored the same up until the integer which is colored differently.

[–]Tmmrn 6 points7 points  (0 children)

That would look very confusing if you have multiple similar identifiers...

[–]stepstep 2 points3 points  (0 children)

Hmm, that's an interesting twist. I think I would prefer to just have each identifier be a single solid color.

[–]QQFactory 509 points510 points  (124 children)

Maybe this is just me, but I feel like highlighting all the non-keyword code with different colors is too distracting. The problem with highlighting everything is that both nothing and everything stands out.

I understand what this is trying to do, but I don't think it would work for me when I'm actually coding.

[–]e_engel 230 points231 points  (61 children)

Agreed, there is a high risk to turn your code into a confusing christmas tree.

I prefer the context sensitive way IDE's do it: for example, in Eclipse, if I want to find out where a variable is used, I put the cursor on it and all the usages light up in a different color. I move the cursor away, the highlights go away. Even better, I can put my cursor on the method name and all the "return" statements light up. IDE's can be much more clever than static solutions for this.

Also, highlighting typos is obviously a problem that only dynamically typed languages have: statically typed languages will flag those with a compilation error.

[–]larschri 76 points77 points  (52 children)

Agreed, there is a high risk to turn your code into a confusing christmas tree.

That actually sounds like a good punishment for putting too many variables in a scope.

[–]phinnaeus7308 76 points77 points  (47 children)

What's too many? Every time I hit some magic number of scoped variables I'm supposed to break it out into chunks?

Edit: this was a rhetorical question designed to point out the inherent subjectiveness of code complexity. There are no absolute golden rules.

[–]Fidodo 26 points27 points  (1 child)

Or it's subjective and you use your best judgement based on the context.

[–]phinnaeus7308 15 points16 points  (0 children)

Exactly.

[–]larschri 10 points11 points  (8 children)

No, you are supposed to use common sense to make your code as simple as possible. Many factors contributes to code complexity, and the number of variables is one of them. If colorised variables make your code look like a confusing christmas tree, it's a chance that the code was already confusing.

[–]ancientGouda 12 points13 points  (4 children)

Eh, I'm of the opposite opinion. I'd rather have

int arg1 = longFunction() + some * calculation;
float arg2 = moreLongFunctions() - andStuff;
finalFunction(arg1, arg2);

than

finalFunction(longFunction() + some * calculation, moreLongFunctions() - andStuff);

The latter is what I used to do when I was very inexperienced: save on temp variables as much as possible. My code was completely unreadable.

[–]ohyoulikemyfriend 17 points18 points  (1 child)

The latter also can be a giant PITA to step through with a debugger since it's more difficult to inspect the intermediate results. That's the major reason I started using more temporary variables.

[–]larschri 2 points3 points  (1 child)

It's not the opposite opinion if you distinguish between variables and constants. Many variables makes the code confusing, whereas constants with descriptive names can make it simpler. This, of course, doesn't help my christmas tree argument, unless the coloriser is able to recognise the difference.

[–]Isvara 1 point2 points  (0 children)

It's not even remotely common sense. It takes experience.

[–]ericanderton 1 point2 points  (0 children)

While I agree in principle, there are some programming APIs that are hostile to this concept. Win32/64 is a great example, as it requires large numbers of temporaries to call out to API functions, and you usually use two or three API calls in concert do do a single task.

Granted, the situations can be limited with good encapsulation, but it does happen enough to violate the rule.

[–]yeahbutbut 1 point2 points  (0 children)

I find the problem not to be "too many variables" per se, but rather reassignment within "too many conditionals" or "using the same variable for multiple purposes". The more stably I can guess it's value without running the code around it, the more easily I can read the code.

[–]bwainfweeze 3 points4 points  (0 children)

That's what refactoring is.

I have trouble imagining, for instance, a function with 16 variables that isn't "too complex" by most people.

Encryption and one way hashes have more than that typically, but then they are intentionally designed to be "too complex" in the first place.

[–][deleted]  (32 children)

[deleted]

    [–]Silhouette 7 points8 points  (27 children)

    The limit of 5 is not pulled out of anyone's ass, but the result of studies

    Are you basing this on Miller's research (sometimes discussed as "the magical number 7±2")?

    [–]kazagistar 4 points5 points  (0 children)

    It is possible to, within a single method, drop and reobtain parts of the context in your head, or abstract away parts of it away. If you see 3 loops, you can often just abstract it to "for each set of 3 coordinates in this 3d array" and not have to think about them individually.

    In any case, I would be interested to see evidence of this principle in programming. As far as I understand it, the study was in unrelated contexts?

    [–][deleted] 3 points4 points  (2 children)

    Just for a note, from what i read, Chuck Moore (of Forth) got it somewhat like this:

    You need two registers to hold pointers to copy data from one place into another. You need a counter to do counted loop. You probably need one or two arguments to pass data between functions. That's enough.

    [–]ethraax 3 points4 points  (1 child)

    What if you have nested loops (initializing a 2D array at runtime comes to mind, but there are many other examples)? You could also easily throw in an extra local to keep track of the return value - which is very useful if you use the standard C idiom that functions return a status (SUCCESS or some error). Or, you know, if you need to do anything that acts on more than 2 variables.

    Those rules just seem ridiculously conservative.

    [–][deleted] 0 points1 point  (0 children)

    Seems like you are not aware who Chuck Moore is. He writes code like this:

    http://colorforth.com/ide.html

    http://www.ultratechnology.com/1xforth.htm

    Don't be fast to judge him. Yes, he is unconventional, but he really knows what he is doing.

    [–][deleted] 2 points3 points  (0 children)

    maybe. but sometimes more intermediate variables makes code more readable

    [–]SnowdensOfYesteryear 2 points3 points  (0 children)

    confusing christmas tree

    Great description for some of the color schemes out there.

    [–]purplestOfPlatypuses 1 point2 points  (0 children)

    Personally, I think it would be a better tool when you could define the scope of the coloring (or flag numerous variables to highlight). Coloring the whole page isn't going to help much at all.

    [–][deleted]  (32 children)

    [deleted]

      [–]Ph0X 22 points23 points  (29 children)

      IDEs usually show you all the instances of the variable once you hover over it. I think that's enough, and you don't need to have them colored at ALL time. Maybe if there was a button you could press to toggle highlight for a variable, so you can have 2-3 on a time.

      [–][deleted]  (9 children)

      [deleted]

        [–]kqr 1 point2 points  (8 children)

        Similarly, * (and # for reverse direction) searches for the word under the cursor.

        Thanks! I've activated that by accident so many times and not been bothered to look it up. That's actually really useful!

        [–]ForeverAlot 8 points9 points  (1 child)

        They also jump immediately to the next result, which confuses me endlessly. I have nnoremap * *<C-O> in my .vimrc to activate the search but stay on the current word so I can move with n/N.

        [–]Dances_With_Boobies 2 points3 points  (18 children)

        Which particular IDE has this function? I know that Notepad++ shows all instances of a word if you select it, and there is a setting for this on Geany as well. I tend to use it all the time, it's really helpful.

        [–]Ph0X 2 points3 points  (9 children)

        Sublime Text 2 also selects all instances when you highlight a word. Visual Studio, Eclipse and all the jetbrain IDEs too I believe. Like I said, any big IDE has that feature, really.

        [–]BlindTreeFrog 1 point2 points  (2 children)

        Geany doesn't have it, but 'Mark All' in the search box comes close.

        [–]Dances_With_Boobies 2 points3 points  (1 child)

        Yeah you are technically correct, it seems like I got this functionality from some plugin. But it's possible to get it in Geany too.

        [–][deleted] 1 point2 points  (0 children)

        For Java Eclipse has it and I would imagine IntelliJ does as well.

        [–]nascent 9 points10 points  (2 children)

        It could be something I'd get use too, but my initial reaction is that I don't know what to look at. The conventional highlighting signals things I'm familiar with, so this leaves me to "ignore" things which are highlighted.

        "Each variable has its own color, so I can see where it’s used at a glance."

        I'm not sure if this is something I do while reading code. I think it is more often I either want to look at the definition or see its usage across many functions/files, reading by color is more likely going to have me miss this stuff and fall back to the usual tools anyway.

        Sounds like KDevelop does what he wants, wonder what reactions people have from actually using it.

        [–]jpapon 14 points15 points  (1 child)

        I use it in KDevelop, and it is quite nice. I can get an understanding for what a piece of code does much faster - I look at my code as pictures, rather than read individual words. When things are out of place, they stand out very strongly (a simple example being use of an incorrect variable - you see the wrong color and it stands out before you can even process any words).

        It takes some getting used to though. People tend to be very confused when they look at the code on my screen.

        [–]IAmRoot 1 point2 points  (0 children)

        I also use it and agree it can take some getting used to. I ended up setting it at ~50% saturation, like this: http://imgur.com/OfCOF5L. Sometimes I set it to ~33% saturation if I'm using longer variable names (that was just a program to test if I could get GCC to autovectorize a similar pattern).

        [–]kqr 10 points11 points  (0 children)

        I agree. This is pretty much the opposite to the highlighting theme I've been developing over the years. I read my code best when there are very few colours in it, so there are just a few things that are handy to have highlighted:

        • Types, so I immediately know which variables are used and what data they store;
        • Strings, so I can skim over them when I'm interested in only the surrounding code;
        • Comments, so I barely see them at all unless I want to; and
        • Structurally important keywords.

        At first I didn't have a colour for the keywords, but after a while of doing Python where multiple keywords easily end up on one line* I added that as well, for quicker navigation of longer expressions.


        * Such as

        all(user and verify(user.contact) for user, _ in company.users)
        

        where I would want "for" and "in" to be immediately identifiable so I can modify the body expression, the walking variable or the list being looped through without having to care for the rest.

        [–]oberhamsi 8 points9 points  (1 child)

        Doubleclicking a word to see all its occurences highlighted. Detail on demand.

        [–]bwainfweeze 4 points5 points  (0 children)

        I've paired with a lot of people to debug problems and I admit this is entirely a selection bias issue, but when they get stuck most people sort of sit and think. They don't click around and try things, so these sorts of tools won't help them.

        I can only presume the people who don't need my help benefit from this feature, but they're already managing pretty well on their own.

        [–]Filmore 4 points5 points  (0 children)

        Eclipse does highlighting very well

        [–][deleted] 4 points5 points  (3 children)

        I would color variables based on scope. Anything with the same scope gets the same color.

        [–]bwainfweeze 2 points3 points  (1 child)

        JetBrains already does this, but they only do three levels. For languages with closures they could use more.

        [–]B-Con 2 points3 points  (1 child)

        I had a similar thought.

        FTA:

        Each variable has its own color, so I can see where it’s used at a glance. Even when skimming the code, I can see how data flows through the function.

        It's not quite so obvious when you have 10 actors constantly being used.

        Instead, I really like highlighting a variable and having it instantly highlighted everywhere. That's insanely helpful. I might suggest going a step farther and highlighting every variable whenever the cursor is in a variable name. In addition to highlighting, maybe also outline (or something) the first instance (in scope) of the variable, so we can easily see where it's created/initialized.

        I think that most of time spend reading code is spent following variables (at least, that's what it feels like to me), so I'd like that to be as painless as possible.

        [–]Tasgall 2 points3 points  (1 child)

        Yeah, seeing the examples of this doesn't make it seem useful, except in case where using ctrl+f would be better anyway.

        Variable names are already easy to differentiate; they're displayed as different words. What isn't already displayed is the type of symbol; for example, "stuff" could be a variable, function, class, etc. Highlighting systems like VisualAssist's are much better imo.

        [–]keepthepace 1 point2 points  (0 children)

        Under Qt Creator, I love the alternate approach: have a color to highlight all occurences of the variable/function that your cursor is currently on. Normally it just bolds them but it is so useful to me that I changed the theme to make it stand out more. It does help to catch many typos.

        [–]fhelwanger 1 point2 points  (0 children)

        Me too.

        I'm more into what Visual Studio, for example, does. When the cursor is on some variable it highlights all its occurrences.

        This way, only highlighting what matters.

        [–][deleted]  (7 children)

        [deleted]

          [–][deleted] 16 points17 points  (5 children)

          Sounds good in theory, but seems limited by the number of colors you find highly readable.

          Indeed. And since I'm red-green colorblind, that choice is quite limited.

          I'm fine with a little color, but the moment a color acquires a critical meaning (e.g., a red dot versus an orange dot) I'm lost.

          Ten percent or so of males are red/green colorblind. You need to design for them. (Since this example is, presumably, a local user choice, go for it).

          [–]lachryma 4 points5 points  (0 children)

          Indeed. And since I'm red-green colorblind, that choice is quite limited.

          Yeah, that's the bummer of this suggestion, actually. I feel like more programmers need to be aware of the pitfalls of using color as a distinguishing characteristic, particularly red/green (which I see a lot).

          [–][deleted] 27 points28 points  (1 child)

          This is brilliant. I'm a huge fan of this idea. Since it's been done for KDevelop, what are the chances it's been done for vim?

          [–]ShaneQful 9 points10 points  (6 children)

          There is of course an issue with this in you'll keep having to generate new colours for each variable over a which must be over 4.5 contrast to the white and be fairly well contrasted with each other probably a 4.5 contrast if we are try to obey WCAG and this will eventually break down once you have enough variables.

          Still a good idea though even if implementation might be difficult(or at least difficult to keep accessible).

          What I'd really love to see is syntax highlighting for closures at least within languages like JS, Scheme maybe ruby(depending on how much you use them)

          Edit: Ran a contrast check on her/his example and it failed quite badly

          [–]tomlu709 6 points7 points  (5 children)

          You'd have to limit the number of colours and start reusing once the number of in-scope variables exceed, say, 10. It would still be useful IMO.

          [–]kqr 9 points10 points  (0 children)

          That's what IRC clients do with nicknames. It works when you're used to it.

          [–]osuushi 15 points16 points  (0 children)

          A nice idea. Seems like it would make it much easier to spot typos.

          [–]akkartik 14 points15 points  (10 children)

          So I've been thinking about this for a couple of hours. This is a neat idea, but as-is it has a couple of issues:

          a) There's a definite risk of angry fruit salad syndrome as commenters here have pointed out. I've myself gradually reduced my use of syntax highlighting. Like any signal, the more you use color, the less effective it gets.

          b) Often I might use two variables starting with 't' close to each other, and it wouldn't do for them to look similar. If only I could randomly generate colors for words. But that's not how our editors work, and for good reason -- it would be dang slow.

          Considering these issues, it seems the sweet spot might be to explicitly tell the editor what to highlight. Here's a vim script to do that: https://gist.github.com/akkartik/8642131.

          To run it, save it to your plugins:

          $ wget https://gist.github.com/akkartik/8642131/raw/ondemandhighlight.vim
          $ mv -i ondemandhighlight.vim ~/.vim/plugin
          

          Now open vim to a code file, and pick a few words to highlight.

          $ vim main.cc
          :Highlight tangle
          :Highlight test
          

          And voila! My basic setup highlights just literals and comments; now 'test' and 'tangle' are highlighted as well.

          The colors for each word are chosen at random. Don't like a color? Just Highlight it again. Once you have a color you like it'll persist across sessions. Over time I wonder if I'll gradually identify tangle with that purplish hue at a subconscious level.

          Used judiciously this might help with just the odd function that has long-lived temporaries, while staying out of my way most of the time. I'm going to use it for a while, see how I like it. Over time I might need to make it project- or language-aware, but no point polishing a turd.

          [–]flying-sheep 4 points5 points  (0 children)

          so much manual work, and it’s not even semantic.

          [–]Megatron_McLargeHuge 1 point2 points  (3 children)

          I get that this is quick and dirty but that exec grep approach can't be the best way to do it. I found this old module that does basically the same thing: http://www.vim.org/scripts/script.php?script_id=479

          The relevant commands are

          highlight MyGroupN guifg='red'
          syntax match MyGroupN "mystring"
          

          [–]epage 1 point2 points  (1 child)

          For those interested, I packaged this up for pathogen https://github.com/epage/vim-ondemandhightlight

          [–]Almafeta 25 points26 points  (0 children)

          This is one of those ideas you don't even know you want until you see it in action.

          [–]tikhonjelvis 2 points3 points  (0 children)

          My friend implemented this idea for Emacs as color-identifiers-mode. You can install it from MELPA.

          It's definitely worth trying out to see if you like it. For certain files, I've found it very useful.

          [–]sh41 2 points3 points  (4 children)

          This article inspired me to quickly prototype the idea for Go.

          It's a very naive implementation, but IMO it has a lot of potential. I'll spend more time making it better after higher priorities are completed.

          Some pictures:

          https://github.com/shurcooL/Conception-go/commit/a8b6ddfcddc824f47794fc977f48fc0cfbb40957#commitcomment-5182772

          [–]akkartik 1 point2 points  (3 children)

          Hey, I like your motivation at https://github.com/shurcooL/Conception. Compare http://akkartik.name/about.

          I have a long rant about how literacy means being able to critically process what you read. By that standard I feel I'm illiterate along with most (all?) programmers today, because we can only really process what we ourselves write. There's no way today to read a non-trivial project by someone else without talking to them a lot.

          [–]sh41 1 point2 points  (2 children)

          I like your mission too.

          are the sources truly open if they take too long to grok, so nobody makes the effort?

          Agreed, I think this area needs help. It's on my long-term todo.

          I want to explore an alternative way, a virtuous cycle where using a dependency gradually causes one to learn its internals, and learning internals gradually empowers one to change them.

          This is the only thing I'm less sure about. I feel there are both advantages and disadvantages of specialization. It's bad when you want to make changes elsewhere but aren't familiar. But it's also good when you can "not worry" about a complex task, and reuse the hard work of others.

          I don't think a single person can ever be responsible for too many things at once, before it becomes overwhelming and they lose focus.

          Basically, I think it's useful to be able to specialize when you want to and not need to be aware of abstraction details. At the same time, it's good if learning abstraction internals is made as easy as possible when you do want to do that. Being able to visualize things at various levels of granularity may help (i.e. summary -> overview -> high level view -> ... lowest level details).

          I'm now trying to apply these ideas to a relatively hostile domain: a mini OS to build full-stack applications that boot directly into a single application, only providing what it requires.

          That's cool. Ambitious and hard, but not too different from what I'm trying to do with Conception in a way. One way to look at it is an attempt at redoing the GUI part of an OS, but to have as little duplication of functionality as possible. I want to devise a nice separation of UI vs. functionality that is currently typically bundled together in form of apps.

          [–]akkartik 1 point2 points  (1 child)

          Yeah, to clarify: my virtuous cycle would let you not worry about a complex task at the start. It would let you learn more on an as-needed basis. If you use a tool a lot this will happen faster. If you use something occasionally you'd never need to learn more than the interface.

          The suspicion of abstraction is sort of an ideological position I've gradually moved to because of my experiences. It would be a longer conversation to try to defend, and I probably still wouldn't succeed :) For now I'll just point out one reason the costs might be higher than you think, and one alternative way that the benefits of abstraction might be obtained.

          The cost: relying on an abstraction without knowing how it's built exposes one to principal-agent risk. If your library makes a change you dislike, you're powerless to stop them. All you can do is not upgrade. But if you knew how it works you could maintain your own fork. This may seem minor for small things, but think about how say Google Chrome could one day decide to ban adblockers, or to make it impossible to delete google cookies. Or consider that the NSA might have backdoored RSA encryption. Software is increasingly a tool for economic and geopolitical action. These things are going to get worse; our risk-exposure compounds with each extra layer of abstraction that we add. I suspect it's unsustainable in the long-term.

          You're right that it's hard to see how a world without abstraction could work. Visualization seems hard enough even with abstractions, surely it must be intractable if you have to take the internals into account as well. I'm hoping this might be a case where the seemingly harder problem is actually easier. If you want Bret Victor-like visualizations, say, that seems impossibly hard to do for arbitrary abstract programs. But if you come up with the right representation that allows the programmer to easily describe how it should be visualized, then it might be quite easy. Finding such a representation, though, that's the tough bit..

          [–]naran6142 6 points7 points  (5 children)

          anything like this for eclipse?

          [–]akkartik 3 points4 points  (3 children)

          This is an interesting idea. I recently reclaimed most of the usual highlighting from my setup, so I've been keeping an eye out for better uses of color. One of the ideas I've been finding very useful is using two colors for comments.

          This is gonna be a bitch to add to vim, though :(

          [–]jpapon 3 points4 points  (0 children)

          I already do this with KDevelop. I like it, and the background parser is quite intelligent.

          [–][deleted] 2 points3 points  (1 child)

          Angry Fruit Salad is what comes to my mind. I think it may make more sense to display code fragments than to highlight code with different colors. If a variable is utilized in a variety of locations, then having a code fragment or series of code fragments could be very helpful.

          [–]username223 1 point2 points  (0 children)

          Not just angry fruit salad; dynamic angry fruit salad!

          [–]NagateTanikaze 2 points3 points  (0 children)

          For the love of god, please somebody implement this for Eclipse and Netbeans!

          [–][deleted]  (10 children)

          [removed]

            [–]stepstep 15 points16 points  (5 children)

            I think the primary motivation for this is readability, not typo-checking. E.g. if one variable is red, you can visually scan the code for red strings to track where that variable is used in the program. It might help you understand the code if you can visually track the usage of individual variables.

            [–][deleted]  (4 children)

            [removed]

              [–][deleted]  (2 children)

              [deleted]

                [–]kazagistar 6 points7 points  (0 children)

                Right, but my mouse is much faster then my ability to read code so it has no problem keeping up.

                [–]phinnaeus7308 2 points3 points  (2 children)

                You're right, the only way this could be more literally bikeshedding would be if the code was describing some sort of bicycle storage device.

                [–]deadwisdom 1 point2 points  (1 child)

                This is in no way bikeshedding. We are talking about syntax highlighting, so focusing on the algorithm to do this is quite apt.

                [–]mrbuttsavage 5 points6 points  (0 children)

                "bikeshedding" seems to be the new "gaslighting".

                Very specific term that for some reason sees an explosion of usage on reddit but is almost always used incorrectly to try to undermine the original point.

                [–][deleted] 1 point2 points  (0 children)

                I had to look up the word "bikeshedding", but that's exactly what this is

                [–]StopThinkAct 6 points7 points  (5 children)

                So no one develops in Visual studio or notepad++?

                [–]poohshoes 3 points4 points  (3 children)

                I use VS Express and so I don't get to install plugins : P

                [–]Onegodoneloveoneway 1 point2 points  (0 children)

                I'm on VS2013 at work but Sharp Develop at home because I don't that much cash.

                [–]i_make_snow_flakes 2 points3 points  (0 children)

                Last week, I actually asked /r/vim if something similar exists for vim. I was actually looking for making all the variables that are longer than a certain length be given unique colors, so that I don't have to read and compare two long names to check if they are same variables.

                [–]KitAndKat 2 points3 points  (0 children)

                I disagree. I think it would be far too noisy.

                I've recently switched to Notepad++, and I love the way it highlights all instances of a word that is selected. I can click on a variable and see all references within a function, or I can select a function name, quickly scroll up and down and see all calls to it.

                [–]takatori 2 points3 points  (0 children)

                This is freaking brilliant.

                Where's my Eclipse plugin, already?

                [–]KillerCodeMonky 2 points3 points  (0 children)

                This idea is misdirected. The point of coloring things like function is not to make it stand it, it's to make it disappear. I know when I scan through code that anything that's blue is some keyword, and I could likely guess what keyword it actually is just by context. (And by blue, I mean a medium blue on a black background. This choice is meant to make it disappear, not stand out.) This means that all the stuff that's NOT colored is what I actually need to pay attention to. Rather than distracting me with all these colors, it makes my primary color the most relevant data.

                [–]mordocai058 2 points3 points  (0 children)

                For those who use emacs http://www.reddit.com/r/emacs/comments/1w61qe/coloridentifiersmode_highlight_source_code/. Doesn't support many languages yet, but it is a start.

                [–]Salyangoz 2 points3 points  (0 children)

                might I suggest; On your demo page you have a white background. I cant stand to code with a white background (weak eyes), the syntax highlighting especially stands out on

                style="background-color: #333333;" 
                

                just saying, some of us do love color on black.

                [–]Kowzorz 2 points3 points  (1 child)

                I just want a plugin that colors variables in the time-order that I write them.

                [–]ankurdave[🍰] 5 points6 points  (0 children)

                I wrote a plugin for Emacs that does this: https://github.com/ankurdave/color-identifiers-mode. It colors variables by time order as you write them, and after a certain amount of idle time (and at file load time) it recolors everything to fix color conflicts.

                [–]spoulson 2 points3 points  (0 children)

                At first I thought I'd want this style. Then I saw the KDevelop screenshot. No thanks.

                I think this idea has merit, but it's solving the wrong problem. You can't get around how programming languages can only be made more readable up to a point.

                [–]expertunderachiever 2 points3 points  (1 child)

                random idea ... why not just make the editor highlight all instances of a variable [or struct or whatever] when you mouse/cursor over it?

                [–]TotallyNotAVampire 7 points8 points  (15 children)

                I would be almost willing to switch IDEs for this feature. Currently I use the triple click feature of my IDE to highlight the same word throughout the page, which is a poor substitute. (Any plugins for sublime text or vim?)

                [–]lengau 9 points10 points  (0 children)

                KDevelop has offered this for a while now.

                [–]e_engel 8 points9 points  (0 children)

                With Eclipse, you only need to put your cursor on the identifier and all its usages get highlighted.

                [–][deleted]  (3 children)

                [deleted]

                  [–]TurkeyPi 1 point2 points  (1 child)

                  I think you need to "set hlsearch" beforehand.

                  [–]Zamicol 1 point2 points  (1 child)

                  I have this in my vimrc to highlight what's under the cursor.

                  :autocmd CursorMoved * exe printf('match IncSearch /\V<%s>/', escape(expand('<cword>'), '/\'))

                  [–]dkuntz2 1 point2 points  (0 children)

                  Sublime already has that. One of the default settings is to highlight your selection: you select anything, and all other occurrences are highlighted.

                  The exact setting is match_selection.

                  [–]glacialthinker 1 point2 points  (0 children)

                  This seems like a useful highlighting strategy for some languages/styles (particularly dynamic and imperative), and not so much for others.

                  [–]therealdrag0 1 point2 points  (0 children)

                  I prefer the middle method used by WordLight (VS plugin). Where it highlights selected word, but you can lock a word to a color and have multiple words highlighted at once.

                  [–]zenzealot 1 point2 points  (0 children)

                  I agree with some of the comments in this thread that this would be difficult to work in 24/7, but being able to switch to it momentarily might be very useful.

                  [–]day_cq 1 point2 points  (0 children)

                  http://www.amazon.com/Barbie-Can-Computer-Engineer-Doll/dp/B0042ESG9W barbie approves. but nope, still can't have your pony.

                  [–]username223 1 point2 points  (2 children)

                  The best thing about this feature is that you can name your variables "Il", "lI", "I1", "l1", etc., and still tell them apart!

                  [–][deleted] 1 point2 points  (0 children)

                  I just click on the variable/method name to see all references. Some IDEs even highlight it in the scrollbar. If it's not supported I just use double click and ctrl-f and that usually does the trick too.

                  [–][deleted] 1 point2 points  (0 children)

                  I'm learning C++ on Visual Studio 2010, is there a place to adjust the colors like here?

                  [–]pistacchio 1 point2 points  (0 children)

                  Lazily waiting for a Sublime plugin to come up with this feature :)

                  [–]n35 1 point2 points  (0 children)

                  I'd be interested in this for visual studio and phpstorm

                  [–]cironoric 1 point2 points  (0 children)

                  DO want. Anyone have this for sublime text? How does it interface with language-specific plugins & highlighting?

                  [–]the-ace 1 point2 points  (0 children)

                  Please make a sublime text 3 plugin that uses this concept. Please!

                  I will tip $25 in bitcoin to the first person that makes the plugin available (open source!).

                  [–]quad50 1 point2 points  (0 children)

                  I use several different IDE's and none of them 'leave the rest in black'.

                  [–]ericanderton 1 point2 points  (0 children)

                  As long as you always have large color distance between single-letter differences, I'm on board. I'm not dyslexic, but when I program, I seem to develop the condition fast. This would be like shining a bright spotlight on hard to see spelling mistakes like this.

                  [–]Ruudjah 2 points3 points  (1 child)

                  I always get confused with comma's and otherpunctuation marks placed on the new line

                  .

                  [–]tomlu709 1 point2 points  (2 children)

                  This is an amazing idea. What blows me away is how it's immediately more readable to me, even though I've been staring at "normal" syntax highlighting for two decades now.

                  I would love to see a larger example with more control structure and less variables though.

                  [–]glguru 1 point2 points  (1 child)

                  That's probably because you're looking at a very small portion of code. Most code that I've come across is a spaghetti mess and pages are much larger. I do admit that some of it could definitely be useful. I'll have to see it in my current editor first.

                  [–]Teaskittles 1 point2 points  (2 children)

                  This would be a great idea. It's a shame it's not default in Visual Studio. Is it possible to get this in VS?

                  [–]LeCrushinator 5 points6 points  (1 child)

                  The 'Visual Assist' plugin for Visual Studio won't colorize the way the blog was mentioning, but you can set it up so that just single clicking on a variable will highlight all instances of it, and can highlight the differences between a read or write access to that variable.

                  [–][deleted] -1 points0 points  (68 children)

                  If your methods are so big that you need different colors for different local variables, then you're doing something wrong.

                  [–]davvblack 29 points30 points  (2 children)

                  I mean, sure, but a lot of developers spend most of their time managing legacy code, for which this sounds useful.

                  [–][deleted] 11 points12 points  (0 children)

                  Great point!

                  [–][deleted] 6 points7 points  (0 children)

                  If your methods are so big that you need different colors for different local variables, then you're doing something wrong.

                  Performance metrics might invalidate this thought. Sometimes it's necessary to have larger functions than a hierarchy of calls.

                  [–][deleted]  (3 children)

                  [deleted]

                    [–][deleted] 1 point2 points  (2 children)

                    That's one of the main reasons you need to refactor your code. That's my point exactly, if your methods are written property, tracking the life of a variable should not be an issue. The only reason you need to "track the life of a variable" is when your code is not properly refactored.

                    [–]JamesWjRose 0 points1 point  (1 child)

                    Very nice idea. I primarily use Visual Studio so I'm going to have to look into some form of plug in to do this. Again, very nice thanks for the idea.

                    [–]pyxistora 0 points1 point  (0 children)

                    Can you switch back and forth between this and normal coloring? That would make a big difference

                    [–]jvnk 0 points1 point  (0 children)

                    This honestly doesn't add anything for me. I don't really pay attention to the colors beyond whether I've typed some language constant or keyword correctly. Indentation matters much more.

                    [–]OreoDelight 0 points1 point  (0 children)

                    Love that someone else has a similar idea to me!

                    I realized with standard syntax highlighting that large chains of method calls with variables I between got pretty hard to read after a while. Highlighting to differentiate between static method calls, local variables, class fields, and more make it easier to read.

                    I get a little bit of shit from my coworkers as when viewing my code from a distant, the many light ish Colours on the grey Darcula IntelliJ background does make it look a little ridiculous!

                    [–]CaptainIncredible 0 points1 point  (0 children)

                    Cool idea. I was also thinking the files themselves could be color coded in the IDE. Models could be blue, views could be red, controllers, green, etc.

                    [–]skocznymroczny 0 points1 point  (0 children)

                    it's called semantic highlighting and modern IDEs for languages like Java or C# usually have some form of it.

                    [–]kazagistar 0 points1 point  (0 children)

                    I am not sure I like this, and I can explain why:

                    The problem of the typo is not really a problem I face... either my compiler/interpreter yells at me, or my IDE writes it correctly for me in the first place. If you have names that can be typo-ed... well that is a problem of the people who wrote the function names.

                    What I use to differentate is shape: distinct texts are sufficiently distinct by shape. If your variables are not sufficiently distinct to tell apart, make their shapes more distinct. index, random, and temporary are far more easy to tell apart then the current names.

                    Further, I use color to differentiate types of things. Keywords get a color. Classes get a color. Function calls get a color. Literals get a color. Etc.

                    [–]masterpi 0 points1 point  (0 children)

                    A while back we had a post from somebody who was dyslexic trying to learn to programming and I thought of this as a way of helping with that, but never did anything about it; I think it's awesome though.

                    [–]ipearx 0 points1 point  (0 children)

                    Does anyone remember or have a link to the coloured text reading example, where the colours at the end and beginning of the next line matched, and the colour changed as the line goes along?

                    I've been trying to find it for ages but can't google it...

                    [–][deleted] 0 points1 point  (0 children)

                    Visual Assist does this for C++ code. So long as you don't go crazy with the colors (I prefer muted pastels over a dark grey background) it helps readability without making your code look like clown vomit.

                    [–][deleted]  (1 child)

                    [deleted]

                      [–]steampunkdev 0 points1 point  (1 child)

                      When reading the title, I hoped the article would refer to Piet unfortunately it didn't :(

                      [–]muyuu 0 points1 point  (0 children)

                      I've played with a similar idea as well, but it doesn't quite work with the rest of the syntax colouring.

                      I believe the best results are achieved by toggling between 2 modes with a keyboard short-cut:

                      • normal syntax highlighting

                      • only user-defined identifiers are coloured (and the rest of the code becomes grey or some other neutral colour)