Search This Blog

Most useful developer tools: ReSharper!

posted on Friday, October 12, 2012

On popular demand, the topic of today is ReSharper! Ever since I started the "Most useful developer tools" tag, people have been screaming in my ear about ReSharper. And it's true, this is probably the favorite tool of a whole lot of developers.

"The legendary .NET productivity tool: find and fix errors and code smells; navigate and refactor; run unit tests and write quality code faster."

ReSharper or R# is an extension for Visual Studio, a "developer productivity tool". It analyses and improves your code on the fly. You can use it to optimize your code, it helps you track errors and even provides quick-fixes. Before I go any further, I should warn you that this tool is not free. It's not cheap either but if you get used to this and use it to the full extend, I can garantee that it will be worth it. More about licensing later on. Back to the topic: ReSharper...

ReSharper is a JetBrains product, which may sound familiar because this is the company behind dotTrace, TeamCity, dotCover and many others.

The latest version is ReSharper 7 which is futureproof as it includes support for Visual Studio 2012, functionality to create Metro style Windows 8 style UI apps and initial support for ASP.NET 4.5 and ASP.NET MVC 4. On top of that they extended their technology coverage with SharePoint and LightSwitch. The new version shows type hierarchy and css style hierarchy, has an improved Generate menu, unit testing improvements (Jasmine JavaScript, PhantomJS), an option to drop unused references (on solution level) and improved JavaScript support, amongst others.

How it works
It's really easy actually, because from the minute you install ReSharper it will start minding your business. Code will be underlined and light bulbs will pop-up out of nowhere. By clicking the little arrow next to the light bulb, you can see and select the suggestions made by ReShaper.

To show you an example of how (part of) it works I wanted to show you how ReShaper makes a suggestion to improve a LINQ query. I had to mess up the code because I borrowed it from a friend, but it's a great example and I'm sure you can figure it out.

We have this simple LINQ query where I wanted to use a First() call after a Where() call, ReShaper noticed that I could do this in one single call. While typing, a green underline indicates that ReSharper has kicked in and has a suggestion on how this can be written better.

When you move your cursor to the front of the line, right before in the line number bar, a light bulb will show up. If you click the little black arrow next to the light bulb you will be shown the suggestion that ReSharper has, to improve this code and some other options. If you click the suggestion, your code will be adjusted.

var address = 
      addresses.Where( a => a.Id.Equals( shop.AddressId )).First();

var address = 
      addresses.First(a => a.Id.Equals( shop.AddressId ));

This may seem like a small change but it makes the code shorter and better. I love the intelligence that ReShaper has on LINQ: if-statements or foreach loops, changes are that ReShaper will suggest a shorter (therefor not necessarely more readable) LINQ query.

Unit Testing
ReSharper also has some functionality for unit testing, including this unit test explorer and shortcuts. This sums up all tests and gives you a very nice graphical overview of all tests and their result. You can easily run or debug a test or rerun the last test.

Another part of ReSharper is that it can overwrite the default Visual Studio keymap to provide you with keys to use all functionality that ReSharper offers to the fullest. On their website, ReSharper also provides keymaps of Visual Studio and ReShaper to list your favourite shortkeys.

Visual Studio keymap:
ReSharper 7 keymap:

Quite frankly, you could write books about this topic (it suprises me that nobody has) but since I'm only a mere blogger I won't go that far. Just get a license or a trail version of ReShaper and get to it! You'll figure out immediate how the ReShaper magic works. To get you started, on each start-up ReShaper will show you a new tip on how to use it, mostly about which shortcuts to use. Yes, you can disable this ;) Below, you can finds some more resources about ReShaper.

You can get ReSharper under a Commercial ($349), Personal ($199) or Academic License ($49).

If you are a teacher or you happen to be the leader of a large open source project then you are in luck, because then you'll be able to apply for a free license.

You can find everything you need to know about licensing here:

Useful links
15 ReSharper keyboard shortcuts you  need to know:
Favorite ReSharper/Visual Studio shortcuts: (link intentionally broken as this website seems to no longer exist)
Most useful keyboard shotcuts for .NET developers (includes ReSharper):
Why does ReSharper want to use 'var' for everything?

ReSharper website:
Visual Studio Gallery about ReShaper:

Could be useful, right?

1 comment:

  1. This comment has been removed by a blog administrator.