views:

2325

answers:

12

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.)

+30  A: 

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!

Conrad
Bah! You beat me to it =)
jonnii
lol. I never considered this.
SnOrfus
It's a seriously great trick.
jonnii
Given how many 'hard-coded' strings a typical application uses for error messages and the like, this would just end up getting in the way. Unless you're one of those people who insists that absolutely everything be fetched from some far-removed XML file.
Whatsit
@Whatsit -- the point is not ZERO strings. The point is for me to see quickly where there are hard coded strings and try as much as possible to eliminate them
Conrad
They have to be hard coded into the program somewhere...
Ed Swangren
like it, I might even do it but I don't think I could face ever seeing red on yellow
annakata
In .net, you have resource files, this is where hardcoded strings belong, let them there
Martin
Kudos. Make em black, on a black background - I think you would battle to type them in, in the first place.
Jonathan C Dickinson
I have been doing the same for years!
decasteljau
BTW, might make sense to have numbers (except 0 and ±1) look horrible too.
Anton Tykhyy
+2  A: 

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

jonnii
+10  A: 

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

womp
+7  A: 

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.

Jon
Very interesting idea!
Jeffaxe
+12  A: 
  • 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.

Reed Copsey
dark background with light foreground are harder to read than light background with dark foreground.
luiscubal
It depends, actually, on the lighting in your office space. In lower lighting situations, I agree. In very bright situations (ie: lots of natural light, or lots of flourescent lighting), dark background is easier on the eyes.
Reed Copsey
@Reed Copsey: Dark background and light text is always harder to read than the other way round. There are hundreds of studies proving it. And it's also not easier on the eyes. The brighter the image we see, the smaller our pupils are and the smaller our pupils, the sharper the image we see! If you have a dark background, with only little text on it, your pupils are wide open and this makes your view much more blurry, because it is much harder to focus that way for your eye. If you choose a dark theme, because a light one is too bright for you, try calibrating your monitor instead.
Mecki
+6  A: 

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.

Ash M
A: 

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.

JoshBerke
+1  A: 

I use a different color for classes and structs.

Jen
A: 

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.

Alekc
+1  A: 

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.

Joan Venge
+1  A: 

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.

Thanks but no thanks, ProggyCleanTT for me!
Benjol
A: 

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.

fatcat1111