ReSharper – Friend or Foe?

resharper

Most developers that have been around the block have heard of Resharper and similar “productivity tools”.  The purpose is to add helpful hints, styling tips, real time code analysis, and many more time saving functions.

ReSharper is a renowned productivity tool that makes Microsoft Visual Studio a much better IDE. Thousands of .NET developers worldwide wonder how they’ve ever lived without ReSharper’s code inspections, automated code refactorings, blazing fast navigation, and coding assistance.

How It Helps

Consistency

Any code inspection and analysis utility is going to help maintain integrity and consistency in your code.  With ReSharper, styles and settings can be stores in a .dotSettings at the solution level, committed to source control, and shared by the team.  This means all developers on the project, will be adhering to the same style guidelines.

Analysis

The code analysis feature is really the powerhouse behind ReSharper.  I can’t tell you how many times I’ve scanned over code visually only to have ReSharper catch a possible null value or ambiguous reference.  Yes, highly trained and meticulous code reviewers can catch the same issues manually, but nowhere near as quickly and thoroughly as an automated code analysis.

Efficiency

I find that I’m pressing Alt+Enter all the time now to see what suggestions and improvements ReSharper has for me.  I don’t implement most of them, but it’s nice to have real time analysis.  The automated code style management is superb for cleaning up code written in a hurry.

And More!

I’m not affiliated with Jet Brains nor do I expect people to land on this page to formulate a decision on whether to ReSharper or not.  Therefore, I will leave the sales pitch to the sales people and redirect you to the produce site to learn more:  http://www.jetbrains.com/resharper/

The Controversy

There’s certainly a bit of controversy over the use of tools like ReSharper.  Many of the comments and concerns expressed are rooted in misunderstanding of what tools like ReSharper are and what they can do.  Out of the box, it’s going complain about everything.  It’s going to add comment stubs where you don’t want them, it’s going to complain about all of your variable names… it’s going to tell you to use var  everywhere…  How dare some application complain about all of my code… right?  Well, maybe.

Many of the complaints stem from developers not taking the time to customize ReSharper and StyleCop to their personal style or company guidelines.  Even further, the development team hasn’t taken time to agree upon architectural and style rules, let alone configure an application to help enforce them.

Here are a few of the comments I’ve heard regarding the use of ReSharper.

Good developers don’t need helper tools like ReSharper to write good code.

There’s a (very) small bit of merit to this.  However, Visual Studio is also helper tool for writing quality code quickly.  Intellisense, F5 to build and test, built in debugger… these are all tools to make development of .Net applications faster and more reliable.  I usually respond to this by reminding the person that .Net code can be written using notepad and compiled using MSBuild.exe via the command line.   However, it’s much easier and faster to use Visual Studio.

I don’t like all of the extra comments and clutter it adds to code.

Easy to resolve.  Create a custom Code Cleanup Profile (which is recommended anyway) and disable style rules 1600-1644.

I don’t need ReSharper.  We have regular code reviews.

Developers are human.  Humans make mistakes.  The more reviewers of the code, the fewer the mistakes slip through, but the more time is expended per line of code.  Tools like ReSharper can take care of the syntax, formatting, and style issues before a code review.  Even better, Resharper can help the developer identify these issues even before the code is submitted for review.  If you remove the need to concern the code reviewer with with style and formatting, reviewers can focus on architecture and business logic, where they can be most effective.

Tips

1. Installation Sequence (The Approved Sequence)

If you plan on using this with integration with StyleCop, make sure you install ReSharper first, then install StyleCop.   Installing StyleCop first leads to integration issues with style rules not properly honored.

2.  Initial Launch (Incompatible Settings)

resharper_warning1

If you’re running a clean install, this setting will pop up on initial launch.  If you have custom StyleCop rules, it’s  a good idea to back them up id you haven’t already.

 3. Removing File Headers

If you accidentally performed a mass code cleanup without configuring a custom profile, you’re likely stuck with a bunch of empty file headers.  This isn’t the most efficient method of cleanup, but it’ll get the copyright statements out of the way.

  1. Open Visual Studio Find and Replace (CTRL+SHIFT+H)
  2. Check “Use Regular Expressions
  3. Add the following expression to the Find field:
    // <copyright file="([^']*)" company="">
  4. Leave the Replace field empty and hit Replace All
  5. When that has completed, add the following expression to the Find field:
    // </copyright>
  6. Leave the Replace field empty and hit Replace All

You’ll still have the default summary elements, but those are a bit less obtrusive.

4. Disable ReSharper for a Solution

There are times when I’m playing around with a sample project and I really don’t want to see all of the blue squiggles from ReSharper’s code analysis.  This is easy to disable for a single project:

  1. In Visual Studio, click the ReSharper menu > Options
  2. In the left menu, expand the Code Inspection section and click the Settings option
  3. Uncheck the box labeled Enable Code Analysis
    resharper_disablecodeanalysis
  4. When finished, click the Save To button at the bottom.
  5. If you would like to disable code analysis only for yourself, and on this solution only, choose Solution “Solution Name” personal
    resharper_disablecodeanalysis_save
  6. The dialog box should close, and show your editor window with no more pesky blue lines!

Conclusion

Tools like ReSharper help you turn out quality code, more quickly while adhering to the coding conventions of your organization.  Take the time to talk with your fellow developers and come up with a convention you can all agree upon.  Then configure ReSharper or similar tool to help you enforce those conventions.  If you remove the need to concern yourself with style and formatting, code reviews can focus on architecture and business logic, as they should.

Leave a Reply

Your email address will not be published. Required fields are marked *