25 July 2007

ReSharper vs C# 3.0 - Extension Methods

I'm going to do several posts about how are we going to support C# 3.0 in ReSharper. I will not dig into much technical details, instead I will discuss end-user experience and product decisions we have to make. These posts are not meant to be description of features, they are rather invitation to discussion - what do you want to see in ReSharper for C# 3.0.

Today I'm going to discuss Extension Methods.

Note: Information, features and ideas contained in this post are preliminary and subject to change in the release version of ReSharper with C# 3.0 support.

In short, extension methods feature provides ability to pseudo-extend some type's public interface via static member. Compiler looks for static methods marked with System.Runtime.CompilerServices.ExtensionAttribute in the static class with the same attribute. It then converts obj.ExtensionMethod(params) into ExtensionClass.ExtensionMethod(obj, params) while compiling. There is also syntactic sugar to mark methods as extensions - you prefix first parameter of ExtensionMethod with "this" keyword:


  public static class ListExtensions
  {
    public static void Process(this List<int> list, int p) {}
  }

As soon as you have instance of List, namespace of ExtensionClass imported into current file and System.Core assembly referenced you can use it as follows:

    void Foo(List<int> list)
    {
      list.Process(1);
    }


What does it mean for ReSharper? Well, besides parsing and resolving, it mostly means updating many features to support extension methods, like parameter information, navigation and search.

There will be a number of context actions, analyses and quick fixes to help with extension methods. For example, you already added "this" to the first parameter of the static member, but still using it in the form of a static method in your code, like this: ListExtensions.Process(list,1). In this case suggestion could be issued to convert to the pseudo-instance form: list.Process(1);

There are also some things that should be done specifically for Extension Methods feature. It would be very handy to have completion feature which lists non-imported extensions and insert using directives when you select one, much like Type Name Completion. Most likely we will extend existing feature to work after "dot" and rename it as "Import Name Completion".

It would be nice to have a refactoring to convert existing static member in a static class into extension method and update all usages to the pseudo-instance form.

When implementing interfaces, ReSharper could also look for extension methods that match interface members and current type, and suggest to use them as default implementation instead of throwing NotImplementedException.

If you have any other ideas about supporting Extension Methods in ReSharper, you are welcome to comment on this post.

23 July 2007

ReSharper 3.0 Screencast Contest

Are you experienced ReSharper user and want to demonstrate the productivity boost you gain with ReSharper?
Do you like it, but cannot afford to pay the cost?
May be you think you are the BEST in using Visual Studio with ReSharper?
Probably, you are evaluating ReSharper 3.0 and have some time to share your experience?

Even if you don't want to compete for free personal license for ReSharper 3.0 Full Edition, you can help us make the most intelligent add-in for Visual Studio even better, smarter and handy. Participate in video contest - show us your coding session!

P.S. If you already spent your 30 days evaluation time, you can download latests ReSharper 3.0.2 EAP builds, which has renewed evaluation period.

12 July 2007

ReSharper 3.0.2 Early Access Program

We opened ReSharper 3.0.2 Early Access Program and now you can download nightly builds of the next bugfix update for ReSharper 3.0.

What is EAP and why do you want to participate?
There are two major benefits in using early builds and participating in the program:

  • You get the cutting edge technologies, new features, productivity improvements and bug fixes as soon as they are implemented. You don't have to wait for release, you can start working more effective immediately.

  • You can influence product development and make sure it works right for you, in your environment, for your development style.
Of course, participating in early access program has its disadvantages, mainly no guarantee that particular nightly or EAP build will work for your project (is there any software currently on the market which does guarantee anything?). However, we install nightly builds every day and rarely have fatal problems preventing us from using Visual Studio and ReSharper.

Why do we need EAP?
We need EAPers for the one simple reason - we can't setup that many test environments people have around the world. Various technologies, libraries, plugins, regional and cultural differences, operation systems and more and more. We can't cover it all. We also can't learn all that styles people do development in. With EAP we can listen to you, and listen early.

How to get most from EAP?
  • Be proactive. If you see something you don't like - tell us. If you feel something works slow - tell us. If you miss a feature, if you think ReSharper should be smarter in particular case, if you find a typo - file a request in our JIRA database.

  • Communicate. It doesn't work in a "fire and forget" style. Don't be anonymous, answer the questions team may ask. Explain why the feature is important and how it should work, give code examples to reproduce a bug, make screenshot when you think you see something wrong.

  • Update and share. I know, it takes some time to download and install new build. I wouldn't suggest to update daily, but if you are interested in taking most from EAP you'd update at least weekly. Tell us and other EAPers how the build is going. Discuss improvements and degradations. Share your experience.

Do you want to join today?

Start EAPing with pleasure! :)

08 July 2007

News of the Weekend

Albert Weinert releases alpha version of the MbUnit plugin for ReSharper 3.0

Dmitry Lomov, ReSharper tech lead, starts blogging about development adventures in the ReSharper project. I'm sure I will learn a lot myself.

I've discovered "draft.blogger.com" and now you can see the poll at the right side of this blog. Would you like to answer?

02 July 2007

Of Tools and Languages

People often discuss tools for languages, often discuss languages, but rarely discuss languages for tools. If you haven't checked the NBL - The Next Big Language - go read it. Until, of course, you don't care about new languages. Here is small quotation:

Most programmers don't realize how often they need to deal with code that processes code. It's an important case that comes up in many, many everyday situations, but we don't have particularly good tools for dealing with it, because the syntax itself prevents it from being easy.


Being tool developer myself, I must say that it is often extremely hard to make desired feature. Not that it is hard to implement the feature, but rather understand how it should work in a particular language and how to "fix" the language. Few examples to illustrate the problem:

Braces in C#
C# block delimiters are braces, symbols "{" and "}", and they are used everywhere, and thus has context-dependent semantics. For a class body they surround methods and properties; for a method they designate start and end of implementation code; inside method they are used for conditional and loop blocks. The problem is that they can easily become unmatched, and thus closing braces change their meaning. The one which was at the method end suddenly becomes closing brace for the loop, method borrows its closing brace from class and all the code looks broken. ReSharper's code analysis goes crazy and highlights the rest of the file in red.

Note, that we don't have such problem in Visual Basic .NET, because we have different "braces" for different constructs and we can detect unmatched "brace" early. However, VB.NET has own problems...

Name suggesting in VB.NET
ReSharper always had name suggesting feature for C# - when you have name of the type in the editor plus space and hit Control+Space you're presented with generated names for local variable or field:



Those names are generated from type name to the left. Note the order - type name first, than declaring symbol name. In VB.NET the order is the opposite. You first give name to the declaring symbol and then specify what type is it.

ReSharper can't help you find the type for the specified name, it would be too slow. We have to invert the order, and we do so by providing "dim" Live Template:



We have similar problem in C# with interface implementation, actually.

So what?
No modern software development process can exist without tools. Continous integration and version control, refactoring and code editing, error detection and code analysis - all these require tools. If the language doesn't support tools, tools cannot support language very well. It requires significant effort to develop tools for unfriendly language and thus less tools appear on the market. At times tool vendors attempt to "fix" language editing expirience with techniques that are not natural to the language itself, because at some moment they need information not typed in yet. In order to get maximum information about developer's intention, we create special features for each intention (like "surround with") instead of understanding what is being typed; just because language forces us to do so.

That said, if you are creating your own language, or even the Next Big Language, be sure to consider tools as a major thing influencing language design.