Question

I usually prefer to code with a black background and white/coloured text but I had never taken the time to change my syntax-highlighting in Visual Studio.

Yesterday, when I finally got around to it one of my changes was to change User Types and User Types (Value Types) to different colors. Without realizing it, I had been using a struct type to pass and return data from methods more than I would have liked.

This change in syntax-highlighting made it very apparent what was going on. So it made me wonder if there were other settings which could provide similar help.

I also usually set my documentation and comment colours to something more washed out and passive so that actual code jumps more at you and makes quickly skimming through code faster.

Do you have any other tips like this which can help spot issues or makes things more readable?

Note: (I've seen this post, but I'm looking more for tips which are functional and provide help rather than purely cosmetic preferences.)

Was it helpful?

Solution

I make strings look horrible. Yellow background. Bold. Red foreground. To remind me that hardcoding strings is generally bad and to try as much as possible to minimize it!

OTHER TIPS

  • For readability -

I recommend a dark (but not black) background, and light (but not white) text. The higher contrast is easy on the eyes, but too much contrast gives me (personally) a headache over time. I also 100% agree on your comment about using a washed out color for docs and comments.

  • For code understanding -

Definitely use different (even if just slightly) different colors for User types, delegates, and value types. This makes them pop, and really helps when you're trying to understand other people's code quickly.

Also, I second the comment about making string literals stand out. I don't necessarily use horrible colors, but I have them a color separate from all of my other colors so they are very noticable.

I also like having Numbers be a separate color. Many times, numbers have some of the same issues as string literals, and having them colored separately makes them stand out for me and helps clue me into places where I should replace a numeric literal with a constant, property, etc.

  • For refactoring -

I've found that it helps me to have a separate theme available where the colors are all exaggerated (bright blue instead of muted blue coloring for interfaces, for example) for refactoring. I use the same basic color scheme I normally use, but with "brighter" colors for each of the types. (I don't like changing color schemes - my brain is kind of wired to my standard set of colors - switching defeats the purpose for me). Having brighter versions makes everything "pop" a bit more, though, so it's nice for refactoring or for trying to understand somebody else's code.

People have put together entire "themes" for Visual Studio. I find that introducing a new settings theme every 6-12 months gives everything a new perspective, although admittedly there are very few themes that I like (I tend to switch between just two different ones).

Check out Scott's article on VS Themes: http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx

Use some nice color for interaces and an ugly one for user defined classes, that helps to decouple things.

The Vibrant Ink theme has some really well thought through things in it. I like to tone down the colors like this a bit htough, but it is a good start.

Why don't you see what works for you? There is a cool theme generator at http://www.frickinsweet.com/tools/Theme.mvc.aspx

Full instructions on the site how to backup your current settings and import the one you create.

Try setting your string literals to be bright red background with bold white text. It'll encourage you not to use magic strings =)

It's not really highlighting but I recently switched to a proportional font after reading some recommendations and found it noticably better.

Before switching my main fear was things would not line up properly but after trying it I realised it worked fine without any apparent disadvantage. Tabs (or spaces) line up the blocks and words that repeat down the page line up because they are made-up of the same letters. My fear was imaginary because I somehow thought I would need words to line up if they were different . This is not the case.

One thing it prevents is aligning words that are in the middle of expressions, not at the left. E.g. In a fixed width font you can do:

string firstName     = "John";
string lastName      = "Smith";
int age              = 30;

Whereas you can't do that with a proportional font. But that practice seems rare these days. Perhaps more of a C or assembly language thing.

I recommend trying it anyway. The internet runs on proportional fonts and so it makes sense to use them, as long as they don't have any disadvantages. When it was recommended to me they claimed it would only take a few days to get used to and that turned out to be true. I find Arial 11 point to be a good choice in Visual Studio.

I use a different color for classes and structs.

Color strings bright so that you immediately notice them in your code. I use green for string on black. On grey I used to use yellow.

Btw I do the same for constants, numbers, etc.

I really like Resharper's colorizing system. Using it you get a little more detail out of your editor. For example: fields, locals and parameters are all different colors. I have no idea why VS didn't include this out of the box.

I always set the brace matching background to something red, and make it bold. This way when I close braces or parens I can see what its being matched against.

I think that it's more important to choose good monospaced font for programming (my choice is consolas, for some other good fonts take a look at this article on coding horror).

Visual Studio's default theme is pretty good imho, maybe too bright if your are working at night.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top