Posts Tagged ‘ReSharper’

Resharper rewrite

Wednesday, February 6th, 2008

OK, so the first ReSharper post was a written statement of resharper joy. However, it’s not the best format for getting me some $$ for ReSharper at work. So, let’s write up an informational document for the people who would make the decisions…

ReSharper is an add-in to Visual Studio that provides Visual Studio with a number of useful features. Overall, they help a developer code cleaner, faster and more efficiently.  ReSharper is produced by JetBrains, the company that also produces IntelliJ, a highly regarded IDE for Java.

Some Key Features

  • Find Usages – this is VERY different from a search. It finds anyplace a class, a class’s method, a property or a variable has been used… if another class has a method of the same name, that method won’t come up-only the ones you want. This is a huge time saver. It’s amazing the amount of time you want to know where something is called so you know if it’s “safe” to change, for instance
  • Related to “Find Usages” is Rename… rename a class at the site of an object declaration, and the class will get changed, the name of the class file, the constructor, all declarations of objects based on that class, and any private variables that seem to have a related name get changed. This is great because any code that’s been around for a while collects artifacts that are misnamed… among other reasons, because something ends up getting repurposed in unexpected ways, or a domain concept becomes better understood. These misnamings were previously a minefield that would inevitably happen. With rename, it’s very easy to give objects the proper name, so the code can become much more intuitive.
  • Highlight unused code. This isn’t really something that a user actively does, it’s one of the many things ReSharper does on its own that helps a developer code better. If a variable or “using” statement is not being used, it colors it gray. Then, unused things can be removed with a quick keystroke. Just another feature at keeping the code clean.
  • If you’re viewing an interface, there’s an option to go to implementors, and it provides a list. Yes, you could do a text search for the interface name, but if you ARE coding with interfaces, this saves time, and is a really intuitive way to navigate.
  • Code completion. If configured correctly, Visual Studio will do code completion, but it requires a code compile for methods to come up. Resharper parses code on-the-fly, so you immediately have classes and methods from other files available as you are working, even if things don’t compile. A little thing, but another timesaver-it saves on typing/guessing errors on your current work even when the code isn’t compiling.
  • It provides better inline method documentation. Again, you could get better documentation on the web, but having it right at your cursor as you type is instant (unlike a web search), and doesn’t require a context switch.
  • It autoparses the ASP.NET aspx files, and makes the content accessible via Intellisense in the codebehind file. Again, you could just spend time flipping back and forth, copying and pasting, but typing in the codebehind and having it pick up the elements in the aspx file helps reduce error (you can intellisense the name out so you KNOW it’s correct) and then you also have the elements’ methods immediately available via Intellisense, so you won’t have to manually type NavigateUrl, savinng type (and avoid possibly mistyping as NavigateURL)
  • Many refactorings are supported, such as “Extract Method” and “Extract Interface”. Refactoring is a way to impove the readability and maintainability of code though safe reogranizations and restructurings. This is something all good developers do as a matter of course, but this tool can help a refactoring happen in a few seconds instead of minutes or even hours. Making refactoring easy is going to make it happen more, which (when done appropriately) is very healthy for a codebase.

Items of note on ReSharper:

  • ReSharper works best on a properly organized Visual Studio project, with classes organized by namespace in folders (this is the recommended way anyway) … but to get best use out of ReSharper on a project that’s legacy and incorrectly set up, you will want to straighten things up.
  • It’s SLOW to open a project. … this is because ReSharper does a pass through of everything for parsing. Granted, things are fine once it does open, but if constantly opening and closing things in VS is your mode of working, You might want to either rethink ReSharper, or your mode of work.
  • It’s a memory hog. This is probably (I’m guessing here) somewhat proportional to the number of classes, since it parses, and holds the definitions in memory so it can do its magic. Anyway, JetBrains says 512 is a bare minimum, and recommends at least 1 gb. I have to say that with my machine set up normally, an ftp program open, and a web browser, I’m going WAY over my 1gb of memory, and am swapping like crazy. I’m guessing here, but looking at my real-world memory usage, I’d say not less than 2gb, and maybe more to be comfortable.
  • The current version is 3.1, but 4.0 for VS 2008 is coming out soon. Anyone who buys 3.1 now gets a free 4.0 upgrade license when it comes out.
  • As this is a plugin for Visual Studio, The developer must have at least Visual Studio Standard (the lowest non-free version, and the cheapest version taking plugins) to use ReSharper.

Cost:

 

  • Single-developer cost $149 for C# only, $199 for C# and VB.net support. They are non-transferrable. The license allows for installation of the software on different computers (at work and/or at home), provided that multiple instances of the software will not be used at the same time.
  • Commercical license is $249 for C# only, $349 for C# and VB support. Commercial licenses are based on a concurrent user model… as many installations as you want, but number of copies legal to be used at the same time limited by the number of licenses purchased. Non-transferable to other companies, but transferable within the organization.

ReSharper = manna from heaven

Friday, February 1st, 2008

This week, after having heard/read many, many times from a variety of developers that ReSharper from JetBrains was essential for any C# developer, I (finally)gave it a go. And after having only worked with it for about three days, I have to say that Resharper just might be the best thing I’ve ever downloaded. Sure, iTunes was fairly cool, and Google earth was nice and all, but the first time I loaded ReSharper up and got things set to use it (more on that later), and it told me what classes/methods were being used, plus it could tell me WHERE (this is very, very different from a text find)… and then, when I used its built in rename function, and it auto-renamed the class, the file name, anywhere that class was used, AND even listed the places it showed up in strings and comments, so those could be gone through separately/manually if desired …. well, that was exhilarating. To think I was no longer bound by the tyranny of my (and others’) old legacy names! That’s one of the things that has always annoyed me about working on an older project. As you get more familiar with a domain you inevitably realize that your original names for things reflected poor understanding, and are in fact misleading… however, you stick with them because of the nightmare it would be to change. Well, no more! (If only you could bottle this kind of glee…)

ReSharper also tells me what is not being used, which is just as important. Of course it’s important to give stuff a quick test after ripping stuff apart, but ReSharper actually encourages better coding. If things are not being used (using statements, variables, etc) it shows them as gray, and you get into a habit of commenting out, or even better, deleting stuff in gray by habit. It’s a simple thing that really helps keep the level of useless cruft down. It also tells you if you can declare variables in a smaller score, keeping things tidy (sometimes I decided against, for the purposes of declaring “starter” values all at the top of a method where they won’t get lost, but sometimes I went along and moved it-which involved just a click)

It even has features like go to implementors of an interface, and if you added things to the interface, you can click to have those methods added, albeit stubbed out with a “Not Implemented” exception… go to interface, or go to inheritors… Just lots of little things that all add up to a more seamless experience.

The initial setup was a fair bit of work, though I really can’t blame that on ReSharper. At work, I mostly support one large site that is several years old, and was really a learning experience for my organization. By the time I came on to the project, it was several years old, and had been through several developers. As a result, it was a hybrid of different approaches, and didn’t quite fit a “usual” .Net setup. To get ReSharper working fully, I had to move a number of directories around, and get the site into a real VS “Project” and “Solution”.. this all took a fair bit of rejiggering and such, but it was definitely worth it.

It’s $200 for the full version that also includes VB support, but I’ve already decided I don’t want to write C# without ReSharper. I’m at a small, mostly non-.net shop, but I hope I can sell my need of this anyway. If not, well, $200 is not too much to have a better working experience…