ReSharper: Don't use Visual Studio without it!

According to IntelliBrains, ReSharper is:

the most intelligent add-in for Visual Studio 2005, 2008 and 2010 that provides a rich set of features to boost individual and team productivity in the world of .NET development.

Ooo! Marketing speak! Allow me to translate:

ReSharper is a Visual Studio add-in that adds over 70 features to the development environment. I linked directly to the feature list on the ReSharper web site, because there are just way too many for me to cover here, and they do a good job of showing you the salient points of each feature. But, I would like to point out a few of my favorite features: (I borrowed the images from the ReSharper web site to save me the time.)

Code Analysis

As I type, ReSharper is analyzing my code, looking for several things:

  • Errors (“that code won’t compile”),
  • Warnings (“that code may cause a null reference exception at runtime”),
  • Suggestions (“the type of that parameter can safely be changed to its parent class”), and
  • Hints (“your code might be easier to read if you invert that if statement”).

ReSharper Hint

This, to me, is the single most valuable feature of ReSharper. I would not code nearly as fast without it.

Navigation & Search

ReSharper offers several “Go To” tools that will significantly speed up your navigation of your code:

  • Go To Type (CTRL+N) takes you to any type in your solution, even by typing just the upper case letters (a feature JetBrains calls “CamelHumps”):

ReSharper Go To Type

  • Go To File (CTRL+SHIFT+N) takes you to any file in your solution – a huge help on huge projects.
  • Go To Symbol (CTRL+SHIFT+ALT+N) takes you to any method or variable in your project.

Refactorings

Here’s a picture of a small subset of the refactoring support in ReSharper:

image

One particularly interesting one in that list is “Use Base Type where Possible…” which is a very good habit. Using abstract classes and interfaces allows you to break coupling in your code. I could write several blog posts about just this one refactoring. Admittedly, though, my use of the refactorings tends toward smaller scale things like “Extract Method” and “Inline Method”.

 

Code Generation

Advocates of the agile practice called Test Driven Development (like myself) have long derided Visual Studio for offering to write unit tests for code that already exists, but not offering the opposite feature – generating method stubs from tests that were written before the code existed. ReSharper fills that gap quite nicely:

ReSharper method generation

If you do TDD in Visual Studio, this feature alone will pay for ReSharper. (And, if you’re not doing TDD, why not?)

Coding Assistance

Here’s a feature I didn’t even know existed until I started writing this article. It’s called “Complete Statement” and it automatically completes the current statement.

When you reach the end of a statement, like this:

ReSharper Complete Statement 1

Simply press CTRL+SHIFT+Enter and ReSharper completes the statement, and places the insertion point exactly where you’d want it, like this:

ReSharper Complete Statement 2

I think I’ll be trying that one out later today.

Code Cleanup

Ever open a file and discover that whoever created it had their tabs set to 2 spaces, making the text too dense and the indentations too shallow for you to quickly grasp the structure of the document? ReSharper can help you there, too. Simply press CTRL+ALT+F to format the file using your preferred format settings.

Code Templates

ReSharper completely replaces the rather limited Visual Studio “Code Snippets” feature with their own Live Templates feature. Here’s an example of their “foreach” template at work:

ReSharper foreach Template

Notice that ReSharper knew which object you were likely to want to iterate over. Very smart. Very useful. To access the feature, press TAB after typing in the name of a live template, in this case “foreach”.

Unit Testing

ReSharper automatically detects NUnit and MSTest-based unit tests in your projects and allows you to run them directly within the Visual Studio user interface. The runner is not perfect – JetBrains doesn’t always quickly add support for new features as they are added to the unit test frameworks. For example, ReSharper 4.5 does not support the NUnit [TestCase] attribute for creating data driven tests. But, I rarely use the [TestCase] attribute when doing TDD tests, which is primarily how I use the unit test runner.

In Conclusion…

If I still haven’t convinced you to take a look at ReSharper, I recommend taking a look at their website before writing it off completely. There are so many useful features that I didn’t cover here, you’re bound to find half a dozen favorites of your own. Heck, even if you’re already using ReSharper, spending some time on their website will likely show you something you don’t know about the product.

0 responses