Two weeks ago, at EKON, Hadi Hariri (www.hadihariri.com) introduced me to a Visual Studio plugin called “JetBrains ReSharper”. I never could associate anything with the name, so he offered to give me a quick demo of the feature set. As I am a happy customer of Castalia in the CodeGear Delphi IDE (www.twodesk.com) and really appreciate the time it saves me to write code, I missed quite a lot comfort when refactoring code in VS. Now I can say “Thankfully there was Hadi …” because ReSharper is definitely the tool to get if you need to write a lot of C# or VB code. Not only does it offer the usual refactoring options like renaming, moving code, extracting methods and the likes, no, it really “digs” into your code and makes suggestions about things you could change or that would make your code better. one of those things is the “null” check. Whenever you use a variable and you have not checked for null you can tell ReSharper to implement the “null”-check for you. One could think that if you write this piece of code:
if (myName.Equals("..."))
Resharper will generate simply
if (myName != null ) { if ...
Nope, it is not that stupid. It first analyses the usage of the variable and might even create a new code level (using { }) so that not only the one line is being properly checked, but also the following lines that depend on that variable.
The null-check is only a very easy example. ReSharper offers extensive anaylsis features that always take your code into account and I have not had a single case that my code did not compile or the code was not yielding the same result as before the transformation. Variable types are also handled perfectly by ReSharper so that you can invoke “type-safe code completion” (my personal term). If you call a method and it expects a certain type, code completion will not only list the types, but will also complete the line for you, if there is only one variable of the matching type in the current namespace available. It is just a huge time safer when writing code!
However, my favourite feature so far is that the software really knows usage patterns. E.g. if you write
List<Customer> customerList = getCustomerList();
And you then write
foreach
and press <Tab> it guesses (!)
foreach ( Customer customer in customerList )
It would not be so amazing if you could not “toggle” the different variable names to be used. E.g. ReSharper offers you many possible variable names if you use camel case or another known way to name your variables. One thing is sure though: if you use ReSharper you definitely have to write a huge amount less code.
There is a trial edition available on www.jetbrains.com . Students get a really fair bargain and there are special licenses for educational institutions available.

No comments
Comments feed for this article
Trackback link
http://www.flickdotnet.de/index.php/2008/03/refactoring-la-carte-jetbrains-resharper/trackback/