Wednesday, November 9, 2011

Leveraging Resharper & plugins.

I have been using resharper for more than 3 years now, and i must admit that with out that i am tad uncomfortable on the visual studio IDE, so very addicted to resharper, to me it is more than just a productivity and refactoring plugin for visual studio , I have learnt clean coding through resharper and its on the fly suggestions to avoid any code smell have worked wonders for me over the years , we call it the ALT + ENTER programming.

Its not only the alt+enter the shortcuts [shortcut sheet permanent part of my desk soft-board] and navigational support makes you feel like the king of the town , you just do a Ctrl + n and you get the search window which supports cool search options like say your class name is MyClass you just type MC in the search window there you go all class having name with M and a C in the drop list for you to choose what you want. there are so many navigational options once you have mastered you can just speed in whilst coding  or while navigating through a solution or even when doing a code review, what more write a complex for loop or a for-each loop on the code resharper will convert it to a complete or part LINQ   for you to learn LINQ on job :-)

Code Inspector
Best is yet to come, should tell you about the code inspector an amazing feature in resharper, you just right   
click on the file or project or even at a solution and select Find Code Issues  will run through the code and point you all the code smells and recommendations which either you ignored in the first place or a piece of code developed by some one who is not using a resharper and hence any these recommendations were not available. now that you have run the code inspector you have the honors to clean up the smells.

The inspector analyzes the solution or which ever level you have selected to inspect and gives out the results in a punctiliously categorized manner as shown below.

which gives you the liberty to prioritize which category you would want correct first , I would certainly go for the Potential code quality Issues, will make sure that i have minimal or no code quality issues. 
and the rest can be cleared as we go along . on expanding shows you the exact line number of the class , double clicking will take you to the problem area [a known issue on version 5.2 what i have observed is that double clicking doesn't work as it should be , must be fixed in version 6 i don't have a license for 6  :-( ] once you are in the pointed issue area all that you have to do is ALT + Enter , apart from the minor issue of double clicking, the inspection process works like a charm.

Refactor
This functionality is the best pal when you are going through Martin Fowler's books on refactoring
just makes the process so easy that you would feel like taking up a contract just to clean up all the code, as you can see on the image it gives you all the options which are only applicable for any selected item avoiding any unnecessary refactoring. 
Extract method and extract Interface have been my best friends :-)



The Var debate
One of the longstanding debates since the C# 3 support for implicit type declaration is the usage of Var type instead of a explicit declaration and here's my view of using a var. 

Use Var here : 
In this case from the RHS we clearly know that scope is a TransactionScope type.and hence take the resharper recommendation of using the implicit type and change it. another area where this can be used is when you have to assign any anonymous type returned by any LINQ statements.

Dont use Var here :
In this case, if you use var any one apart for you wold know what 
is the type for Order ID, this holds good for any primitive data types. 



the above is purely for the readability and maintainability perspective and would not have ant performance or memory impact.

Resharper has a fairly long list of plugins available among which the power tool being my favorite lets take a look at what in store, firstly you will meet the agents belonging to the code practices and improvements category 

  • Agent Johnson
  • Agent Ralph
  • Agent Smith

  • then would be the explosion of  ReSharper PowerToys unzip to know the list of  toys one to  look out for is the tool for Analyzing cyclomatic complexity of method bodies.[VS2010 code metrics covers this anyways]
    to name a few more Style cop and TDD helper and so on... more here

    with support for C#, VB.NET, XAML, ASP.NET, ASP.NET MVC, JavaScript, CSS, XML and unit testing, that's almost all support, definitively a must have for all developers.

    Start sharping your code if you are not yet  !!   

    No comments:

    Post a Comment