Why You Should Use Resharper to Manage or Refactor Your Code

Share on FacebookTweet about this on TwitterShare on LinkedIn

Share on FacebookTweet about this on TwitterShare on LinkedIn

Coding isn’t always easy and managing or refactoring your code (improving the design without changing the external behavior) wasn’t always easy. The days of hunting and pecking through code blocks and then crossing your fingers when performing a find and replace so that everything is replaced in the proper context or location, are now thankfully long gone. Instead, developers have access to a suite of refactoring tools that provide hundreds of easy-to-use processes that help the developer spend less time managing the editing of code and more time writing cleaner, clearer code.

Refactoring tools are available across many platforms as feature-rich add-ons to integrated development environments (IDEs). Common refactoring tools include ReSharper, JustCode, and CodeRush. Some IDEs are attempting to flesh out their own built-in refactoring tools, like VS Commands for Visual Studio. Each offers a menu of refactoring tools for the average developer. However, one tool in particular that has proven to be extremely popular is JetBrains’ ReSharper, which was built as a very robust add-in to the Visual Studio IDE, and has quickly become an indispensable tool for the .NET developer.

segue-blog-resharper-to-manage-code

What is ReSharper?

To be honest, ReSharper has such a wide offering of refactoring tools that using all of them would be quite a feat. Even referring to ReSharper as a “refactoring” tool sells its capabilities short. The tool provides Code Analysis, Navigation and Search, Code Assistance, Code Generation, Unit Testing, Internationalization, XAML Editing Tools, Cross-Language Functionality, and more. The list of functionality is surprisingly long and only continues to grow with each iteration of the product. The large number of offerings also means that you can feel confident in knowing JetBrains has lifted the hood on .NET and has worked very hard to figure out how all the moving parts could or should work best together. In a lot of cases, too, they even provide assistance in re-writing certain code blocks to improve efficiency, readability, adherence to generally accepted coding practices, or all three.

There are so many refactoring tools within ReSharper’s arsenal that none of us really use them all. However, there are certainly some that are such wonderfully simple, powerful, and miraculous time-savers that they have been adopted and used regularly by nearly all of our .NET developers. If you are looking to increase your coding productivity, then I highly recommend investing some time in discovering what ReSharper (or even any of the other refactoring tools) has to offer.

Refactorings

This is the original and still the best feature of a tool like ReSharper, because the extent to which you can refactor the code base continues to grow. Again, the folks at JetBrains are pretty smart about how .NET coding works, and here they’ve provided an incredibly broad range of tools to significantly cut down code maintenance times. Regardless of which tool is used, the best thing about them is they know how changes should be propagated across the entire code-base.

Change Signature

For example, if you need to add or rename a parameter in a method signature, the old method was to find all instances of the method in the code base and manually change the method name and add the new parameter value. With ReSharper you don’t worry about that! Simply highlight the method, select ‘Change Signature’, make the necessary changes and then ReSharper will update all instances of the method regardless of where it is in the code base, with the updated method name and new parameter. Voila! It will even rename the parameters used in the method (if you’ve changed their names, too.)

Extract Class & Extract Method

You can effectively create either two classes from a section of code in a bloated existing class, or you can create a method from a section of highlighted code. For the extracted class, ReSharper will suggest new methods and properties based on the content of the selection. For the extracted method, ReSharper is smart enough to suggest parameters needed by the method (based on the selected content).

Rename

This is probably the smartest of all. This is not the same as “Find & Replace” because that works off a simple text specification. For this feature, ReSharper will rename any symbol in the code base. As such, ReSharper will know exactly which items match the text name based on context and usage. In my opinion, this is the hands down best and safest mechanism for find/replace.

Code Generation – Create from Usage

When you know a method is needed that’s not yet written, you can call it in code to create the method stub. ReSharper will create a brand new method based on the name you’ve already used in the call and will also generate method parameters based on what you’ve passed into the method call itself (assuming those parameters are also valid within the existing code block).

Coding Assistance

A lot of ReSharper’s power is surprisingly subtle, yet it’s so addictive that you can easily forget that its features are not an intrinsic part of the IDE. ReSharper’s Coding Assistance tools alone are worth the price of the add-on. (Although, to be fair, Visual Studio provides some of these tools, too; a lot of times ReSharper does them a little better, though.).

Syntax Highlighting

Anything and everything you can think of in your code base that should be smartly distinguished by color is done so via ReSharper’s syntax highlighting. This is one where Visual Studio does this pretty well but ReSharper does it better.

Symbol Completion & Smart Completion

ReSharper works across all of the languages within the Visual Studio IDE. When typing a symbol then dot (“.”), ReSharper automatically knows the context-sensitive items to display in the Intellisense. It is even smart enough to know when a dynamic property has been assigned to a javascript object in one line, and  when the same object is declared a few lines later, typing a “.” will display the dynamic property name in the Intellisense. ReSharper can even filter the Intellisense dropdown to only display the appropriate parameter names/types.

This is only a small sample of what ReSharper and other refactoring tools have to offer. They are becoming so good and so comprehensive that all you have to do is use them for a short period of time and you’ll quickly start to wonder how you ever coded without them.

Need Help? Contact us