Archive for the ‘ReSharper’ Category.

Null Coalescing Operator

I learned something new about C# 2.0 today while using ReSharper: the null coalescing operator which is represented by the ?? keyword.  According to the C# ECMA standard (p.63-64),

The result of a ?? b is a if a is non-null; otherwise the result is b.  Intuitively, b supplies the value to use when a is null.  When a is of a nullable type and b is of a non-nullable type, a ?? b returns a non-nullable value, provided the appropriate implicit conversions exist between the operand types.

In practice, the null coalescing operator can be achieved through the following refactoring (a simple ALT+ENTER which ReSharper will do this automatically for you.  It’ll ask you whether you want to “Replace ‘?:’-operator with ‘??’”).

object Foo()
{
  object someObject = getObject();
  return someObject == null ? “Object is null” : someObject; // <--- This statement will be refactored to use the null coalescing operator

  // Prefer the ternary operator over using conditionals for easy readability.
  // In other words, avoid writing the following statements:

  // if (someObject == null)
  //   return “Object is null”;
  // else return someObject;
}

This is how we can refactor the above method to use the null coalescing operator:

object Foo()
{
  object someObject = getObject();
  return someObject ?? “Object is null”; // <--- This is it.
}

In other words, if the left-side operand is null, the value of the right-side operand will be returned; otherwise the value of the left-side operand will be returned.

It is here! ReSharper 4.0!

Get it while it’s hot!

There are two different ReSharper 4 Default Keymaps:

  • Visual Studio scheme (PDF)
  • ReSharper 2.x/IDEA scheme (PDF)

Becoming a ReSharper Jedi with James Kovacs

I’ve received some good input from people who’ve read “The Case for ReSharper in the Enterprise“, and thus I’ll continue on the same theme in this post. 

James Kovacs has published a couple of short screencasts (less than 10 minutes each) on discovering the power of refactoring and productivity that ReSharper offers to .NET developers.  I highly recommend you to see them in groups (during lunch hour maybe? with one or two slices of pizza and green tea of course…) if you want to see for yourself what ReSharper can do for you when coding.

The links to the screencasts are:

P.S. ReSharper 4.0 is now available as a CTP.

ReSharper 4.0 BETA Is Here!

JetBrains has released its public beta release of ReSharper 4.0 today!

Have a safe weekend and great refactoring! :)

JetBrains releases a stable nightly build EAP of ReSharper 4.0

The warm product was released today as a nightly build.  It’s worth checking out.  I’m so impatient ever since developing with C# 3.0.  Some people referred me to CodeRush/Refactor Pro! but I don’t feel like learning new shortcuts all over again…Keep the faith Brian…keep the faith!

Check out this page to download ReSharper (EAP) and view the fixes for this release.

By the way, anyone of you (dear Reader) uses CodeRush/Refactor Pro?  The license fee seems much lower than ReSharper’s, but that apart, what do you think about it?  Some people also told me that they use both at the same time.  Wow.

The Case for ReSharper in the Enterprise

I’ve been using ReSharper as a complement to Visual Studio since version 2.0 of JetBrains‘ powerful refactoring and productivity tool in my .NET projects. ReSharper, which fully supports both C# and VB.NET, is not only a time-saver when applying refactoring patterns but is actually a great assistant in making you a better .NET developer. In a few moments, I will provide my thoughts that support these statements and more.

In my previous job at a small ISV (seriously, we were three), my boss which is very much on the technical side of business made sure to provide us with the necessary tools and resources to deliver high quality projects to our customers. In order to achieve this “high quality” level, we had to make sure that our productivity was high, our “comfort zone” was in the green and the tools available to us would support both of these needs at a minimum. That being said, he provided for us a dual monitor setup (I wish we had three…but then again I wish for a lot of things in life), powerful machines, comfortable chairs…and reliable software tools such as modeling tools, profilers, code analyzers, etc. Of all these things, I believe that software tools are the most important because even though your productivity might slow down if you’re lacking a second monitor or that chair isn’t as comfortable as it should be (one benefit of having a bad chair is that it reminds you to get up and walk around every 15 minutes which is very good for your back), you can radically lower your productivity and your quality output if you’re not provided adequate tools to fulfill your job. In my software toolbox, my favorite one is a refactoring tool because it helps me to reduce code duplication, augment code intention when applying refactoring patterns, and supports TDD from the get-go. In my .NET development toolbox, this tool is satisfied by ReSharper.

Unfortunately, there are many companies that produce software that don’t provide these kinds of necessities to their developers. My guess is that their CIO or technological managers aren’t as technical as they should be or they don’t see these necessities as a real necessity (maybe it doesn’t align with their current fiscal year’s objectives, who knows…). My goal in this post (and with your comments) is to present a case to management that developers who aren’t provided the necessary and essential tools to help them in their daily development tasks is like sending a soldier to combat without the appropriate gear (it’s the first example that popped out in my mind…I must confess that I’m watching the late night news as writing this post…and what else is there to talk about than the war in Iraq itself?). The tool I’ll focus on is ReSharper (but feel free to share your own tools as well!)

All right, here we go. As you may know, the .NET framework base classes and interfaces are all grouped in various different logical namespaces. According to Patrick Smacchia’s lately post on on the number of types in the .NET framework, there are close to 933 namespaces and 39 509 types alone in the framework. I doubt that Kim Peek can memorize all of them. A tool like ReSharper actually is a time-saver in this scenario because it is intelligent enough to assist you in importing the right namespace for a type. This is extremely helpful, because when programming, you really want to focus on “the type I need/want to use” and much less on the “which namespace holds the type I need/want to use?“. I don’t know if it happens to you, but I tend to lose my concentration whenever I’m shifting away from focusing on the real task at hand (such as browsing the MSDN documentation or the Object Browser to find a compatible type, a base class, an interface or a namespace). So this is my first argument for giving a ReSharper license to your employees: a refactoring tool like ReSharper reduces a developer’s time and increases her productivity by letting her focus at the real essence of the application (the code) and less on the plumbing (figuring out which one of the 933 namespaces holds our type).

Furthermore, a tool like ReSharper actually helps developers who are novice in object-oriented programming. I’ve been doing consultancy for a while enough to know that not many .NET developers have sharpened their OO skills compared to Java or C++ folks. I’m glad to hear that the ALT.NET movement is making a serious effort in this area, but until this is mainstream, tools like ReSharper can be a valuable resource to help us in this direction. For example, ReSharper will actually propose you to use a more general type (such as a base class or an interface) whenever possible (check out the screenshot below). This is extremely useful as it helps to fulfill the principle of favoring interfaces over implementation (which decreases coupling to a specific type) and facilitates testing and maintenance. Therefore, my second argument for giving a ReSharper license to your employees: a refactoring tool like ReSharper can make your developers more aware of some key OO principles. And if your organization takes time to do some code reviews, more people can participate in sharpening their OO skills at the same time.




I’ll give a final argument to my case for enterprises to supply their developers with a tool like ReSharper (the rest of this case will be continued by your comments and ideas). Whenever you’re doing some contracting for another client, or your changing jobs with another organization, most of the time you’ll have to familiarize yourself with another coding standard or coding guidelines. This is the perfect situation where a tool like ReSharper can leverage this pain since it can assist you in coding to a standard. All you have to do is provide the tool with a coding template and that’s it. That’s actually how it should be. I once heard that Albert Einstein didn’t even know his own telephone number and when asked why that was the case, he simply responded “I don’t need to remember my own phone number, I can just look it up in the phone book!”. It’s the same scenario in this case. Why memorize and remember such a static information like a coding standard when it can actually be enforced by a tool? The less I have to remember things, the better I am at performing my work because I can concentrate more on the essential and less on the “plumbing”. The beauty of a tool like ReSharper, is that you can tell it to format your code according to a given template whenever you want. That’s my third and final argument for convincing management to provide a tool like ReSharper to their developers: it helps them (once again) to focus more on the essential code and less on the “esthetics” aspects of it by delegating multiple coding standards to the tool. This guarantees that the customer will always have a codebase that respects her standards.

Of course, there are countless more reasons to provide refactoring tools like ReSharper to your developers. I highly recommend to take some time and view the features offered by this incredible product. I know some developers that actually purchased their own licenses or even are using some cracked version of the tool just to satisfy their own needs (man, it sounds like being addicted to drugs or something) because at the end, the tool proved itself more than valuable. This shouldn’t be the case. Supplying the right tools to your developers is a great way to let them know that you care about their work, and as a result help your organization to increase in both maturity and capability.

Granted, ReSharper isn’t a silver bullet, but in many cases it provides us with the support we need to concentrate on writing essential code while giving us the opportunity to easily apply refactoring patterns and driving our design with TDD. That alone gives us a boost in productivity, which can vary on the user’s experience with the tool (see the ReSharper Jedi video for more info) and quality. That, I believe, is a bullet strong enough to harm the werewolf constantly that frightens developers to respond to changes, refactor their code, organize their unit tests and more.

My Visual Studio 2008/Resharper Theme

A while back, Scott Hanselman published a post on “Visual Studio Programmer Themes Gallery“. It never occurred to me the idea that maybe a darker scheme could be better for my eyes. That same afternoon, I started to play with some fonts and colors, and came up with the following scheme. This Visual Studio theme is highly inspired from John Lam’s elegant “Vibrant Ink Port” and the Resharper style is based on my own Canadian taste. Actually, if you don’t have Resharper installed, the fallback theme will be a slightly modified version of the “Vibrant Ink Port” scheme.

Click here to download this Visual Studio 2008/Resharper theme. I have only exported the “Font And Colors” options so that you can still keep your other settings. If you’re using Visual Studio 2005, edit the file with your favourite XML editor and change the ApplicationIdentity’s version to 8.0.

Figure 1. A sample of C# code’s “look and feel” with the theme.

Figure 2. A sample of XAML code’s “look and feel” with the theme.

To import the settings, follow these simple steps:

  1. Launch Visual Studio 2005/2008
  2. Go to Tools -> Import and Export Settings…
  3. Click on “Import selected environment settings“, then click on Next
  4. Backup your current settings if you want then click on Next
  5. Click on the Browse… button, select the vssettings file, then click on Open
  6. Finally, click on Finish to activate the scheme

ReSharper 3.1 Released and Getting Better Than Ever!

JetBrains, makers of some of the best .NET development tools for Visual Studio, have released ReSharper 3.1 on this Christmas Eve. I have been using ReSharper since version 2.x came out, and I must say that it is very hard to develop without this tool. I don’t normally depend on a tool to drive my code, but this one is an exception, since it boosts productivity, quality and speed during development.

This new minor version provides a nice feature, Solution-Wide Analysis, which analyzes all projects in your solution looking for errors on-the-fly, without compiling it first. To enable this task, all you need to do is explicitly switch on the feature (make sure you have loaded a solution before enabling the feature), and then, after it analyzes your solution, view the list of errors in a dedicated window (Figure 2 shows you how to activate that window). You can also tell the analyzer to skip some files or folders (see Figure 1 for more information). Depending on the size of your solution and the performance of your hardware, this operation might take some time to execute (see Picture 3 for more information).

The most important characteristic of this feature is that you don’t have to compile the solution to get the list of errors, which can be of a great benefit for a solution consisting of a handful of projects which might take more time to compile than performing the Solution-Wide Analysis.

See what I meant by boosting a developer’s productivity, quality and speed? Check out the release notes for ReSharper 3.1.

Another cool gift from JetBrains is that if you purchase a license for ReSharper 3.1, you will get a free license for the next major release of the product, ReSharper 4.0.


Figure 1. ReSharper’s Solution-Wide Analysis window (new in version 3.1)
image

Figure 2a. Activate the Errors in Solution window
image

Figure 2b. This is the Errors in Solution window
image

Figure 3. The Solution-Wide Analysis operation might take a bite out of your hardware’s performance
image