We are proud to announce the release of ReSharper 3.1. The new version not only brings many bugfixes, improved stability and new features, but also provides the opportunity of free upgrade to v4.0 for new purchases.
This minor - but extremely upgrade-worthy - release extends support for various technologies and languages including ASP.NET, VB.NET and XAML, and introduces the amazingly powerful Solution-Wide Analysis. The new feature lets you instantly find compilation errors in your whole solution - not just in the currently opened file.
Download it now and review release notes.
20 December 2007
18 December 2007
One Line - Filtering Popup Lists
When recent files list is open, you can start typing and list will get filtered to show only items which contains entered text. This feature also works in all "Go to" popup lists, like Go To Usage or Go To Inheritors.
17 December 2007
One Line - Moving Code Around
Holding Ctrl-Alt-Shift and pressing arrow keys moves code around. It can move members up and down, reorder parameters in place, move statement within a block, move statement out of block or into block, and move XML tags around. Note, that it is just textual editing, it doesn't check if such move would be valid or fix any references.
16 December 2007
One Line - Naming Style
If you configure your field naming preferences in options (Options / Languages / Common / Naming Style), ReSharper will derive better names for properties and other entities when generating code.
12 December 2007
One Line - Create File From Template
You can use Alt-Ins in Solution Explorer to create file from one of your File Templates in the current folder.
Feature of ReSharper 3
Feature of ReSharper 3
11 December 2007
ReSharper and Visual Studio crash on x64
For those who experience problems running ReSharper on x64 machines, here is the bug description on Microsoft Connect.
Updated 13 Feb:
Deep in the comments to the aforementioned request there is information about how to obtain hotfix:
And also:
It turns out that this crash is the result of a bug in the Wow64 layer of Windows x64 (XP/2003 – it has been fixed in Vista x64) and only manifests itself when another app globally hooks all Windows messages.
We are currently working with the Windows servicing folks to get a hotfix produced.
Updated 13 Feb:
Deep in the comments to the aforementioned request there is information about how to obtain hotfix:
If you are experiencing this issue you will need to contact Microsoft Customer
Service & Support (http://support.microsoft.com) and ask for the Windows
Hotfix with ID 947841. If you have any difficulty in obtaining the patch
ask the CSS representative to contact me (Sean Laberee).
I am also pleased to announce that we have created a workaround in VS 2008 SP1 which eliminates this problem and the need for the patch. That workaround is queued for checkin to our build process and will be available in the Beta of the service pack.
And also:
A quick update on the windows patch. I've confirmed with our support team that if you call in for this hotfix you will not be charged. They will set up a "Hot Fix" case for you. I've also received a report that there was some confusion as to whether this fix is for Win2003 or XP. I've confirmed that this fix does in fact apply to both releases.
28 November 2007
ReSharper Club - Are You In?
Well, not really a club, but we thought you may wish to have cute ReSharper banner on the side bar of your blog, or project site, or may be print it and put on the wind-screen of your Porsche :) I have one right here, in my blog! Ah, well, I mean banner, not Porsche...
Want it? Go to The Banner Builder page and assemble it as you like. Don't forget to put the result on your website!
Want it? Go to The Banner Builder page and assemble it as you like. Don't forget to put the result on your website!
22 November 2007
ReSharper and Visual Studio 2008
Since there is a lot of buzz about Visual Studio 2008 release, I thought I would stand and say about ReSharper in relation to this fact.
Released version
ReSharper 3 can be installed with Visual Studio 2008 and works fine, unless you are using C# 3.0 new features, like lambdas, LINQ, extension methods and such. This constructs are not parsed by ReSharper 3, which was developed to support C# 2.0 only. It is not only highlighting which doesn't support C# 3.0, it is all the core and code intelligence. For example, rename refactoring will not find usages of extension methods and will not update them.
There also could be some glitches, even if you don't use new C# 3.0 constructs. This is due to the fact that C# 3.0 compiler is always used in Visual Studio 2008 C# projects, regardless of target framework. It it is not widely discussed, but changes in language are wider than just several new features. There are differences in type inference in generics and candidates lookup for binding, to name few. If you happen to hit this special cases, ReSharper could behave incorrectly.
If you are really-really going to immediately jump C# 3.0 wagon, you can disable highlighting (Options / Code Inspection / Settings) and switch to Visual Studio native intellisense (Options / Environment / IntelliSense / General). This will help a bit, but still you cannot trust find usages results, refactorings and many other features.
There was also reported weird problem with Visual Studio 2008 and ReSharper installed on x64 computers - opening Visual Studio's Find dialog crashes. We are currently trying to reproduce this problem. If you experience this problem, please tell us!
Some people tend to ask for quick-and-dirty hack for ReSharper 3 so that it just parses the code and don't do anything intelligent with C# 3.0 code. It is not possible. Details are not important here and are pure technical.
Next version
ReSharper 4 is in very active development. Its main purpose is to support C# 3.0 in all of its beauty. This means not only parsing and code intelligence, but also new analysis, refactorings, context actions and quick fixes. We are concentrated on making your development experience with C# 3.0 as smooth and pleasant as possible.
Currently, we have support for implicity typed variables and arrays, extension methods, object and collection initializers and automatic properties. As soon as we complete support for lambdas, queries and anonymous types, we will open Early Access Program. We plan to achieve this goal in January, 2008.
From this point you will be able to download EAP or even nightly builds and try full power of ReSharper 4 with your new C# 3.0 code.
In regards of upgrade policy, we are currently in the process of deciding upgrade cost, who qualifies for free upgrade, or if we want to do something special about this release. I will post about it as soon as I can.
As for release plans, we are aiming at 2008'Q1, hopefully sometime soon after Visual Studio 2008 launch event in February. ReSharper 4 will be available to general public via Early Access Program at least for 2 months before release.
If you have any questions, do not hesitate to ask in comments.
Released version
ReSharper 3 can be installed with Visual Studio 2008 and works fine, unless you are using C# 3.0 new features, like lambdas, LINQ, extension methods and such. This constructs are not parsed by ReSharper 3, which was developed to support C# 2.0 only. It is not only highlighting which doesn't support C# 3.0, it is all the core and code intelligence. For example, rename refactoring will not find usages of extension methods and will not update them.
There also could be some glitches, even if you don't use new C# 3.0 constructs. This is due to the fact that C# 3.0 compiler is always used in Visual Studio 2008 C# projects, regardless of target framework. It it is not widely discussed, but changes in language are wider than just several new features. There are differences in type inference in generics and candidates lookup for binding, to name few. If you happen to hit this special cases, ReSharper could behave incorrectly.
If you are really-really going to immediately jump C# 3.0 wagon, you can disable highlighting (Options / Code Inspection / Settings) and switch to Visual Studio native intellisense (Options / Environment / IntelliSense / General). This will help a bit, but still you cannot trust find usages results, refactorings and many other features.
There was also reported weird problem with Visual Studio 2008 and ReSharper installed on x64 computers - opening Visual Studio's Find dialog crashes. We are currently trying to reproduce this problem. If you experience this problem, please tell us!
Some people tend to ask for quick-and-dirty hack for ReSharper 3 so that it just parses the code and don't do anything intelligent with C# 3.0 code. It is not possible. Details are not important here and are pure technical.
Next version
ReSharper 4 is in very active development. Its main purpose is to support C# 3.0 in all of its beauty. This means not only parsing and code intelligence, but also new analysis, refactorings, context actions and quick fixes. We are concentrated on making your development experience with C# 3.0 as smooth and pleasant as possible.
Currently, we have support for implicity typed variables and arrays, extension methods, object and collection initializers and automatic properties. As soon as we complete support for lambdas, queries and anonymous types, we will open Early Access Program. We plan to achieve this goal in January, 2008.
From this point you will be able to download EAP or even nightly builds and try full power of ReSharper 4 with your new C# 3.0 code.
In regards of upgrade policy, we are currently in the process of deciding upgrade cost, who qualifies for free upgrade, or if we want to do something special about this release. I will post about it as soon as I can.
As for release plans, we are aiming at 2008'Q1, hopefully sometime soon after Visual Studio 2008 launch event in February. ReSharper 4 will be available to general public via Early Access Program at least for 2 months before release.
If you have any questions, do not hesitate to ask in comments.
16 October 2007
C# 3.0 Automatic Properties - Incomplete Feature?
Well, C# 3.0 is nice language. However, digging into details of every new language feature while developing ReSharper support make me wonder about little things that look like incompleteness. Today I'm going to wonder about automatic properties.
This code is correct in C# 3.0, there are no missing "abstract" or get/set bodies. It simply means that compiler will create field and accessors code for you:
What is cool about automatic properties? Obviously, ReSharper users don't benefit much from shorter code - who types properties by hand these days? However there is one very important thing:
If you want to know how this property gets its value, you no longer need to search for both field and property usages. You don't need to synchronize field and property types, once you decide to change it. Also, access to the class attribute (in OOP sense) is fully controlled right at the place of the declaration. You can limit it as you wish:
This way you declare that "Name" can be modified only within the class itself, but can be read from outside.
So, what is missing from this language feature?
Initializer.
I may wish to initilize property to some non-default value. Like this:
Read-only automatic property
In the example above, I don't actually need setter.
Obviously, you don't need read-only automatic property without initializer. Also note, that such property can never change its value, even in constructor, unlike readonly fields.
Attributes on generated fields
If you use simple event form and compiler generates field for storing delegate, you can apply attribute to the generated field by using attribute target:
I wish I could do the same with automatic properties:
Conclusion
Few simple improvements over existing implementation could make automatic properties much more useful in everyday professional .NET development. Unfortunately, language designers decided:
I'd prefer the advanced version, if I had a chance to choose.
public string Name { get; set; }
This code is correct in C# 3.0, there are no missing "abstract" or get/set bodies. It simply means that compiler will create field and accessors code for you:
private string __someGeneratedFieldName;
public string Name
{
get { return __someGeneratedFieldName; }
set { __someGeneratedFieldName = value; }
}
What is cool about automatic properties? Obviously, ReSharper users don't benefit much from shorter code - who types properties by hand these days? However there is one very important thing:
Less complexity to manage.
If you want to know how this property gets its value, you no longer need to search for both field and property usages. You don't need to synchronize field and property types, once you decide to change it. Also, access to the class attribute (in OOP sense) is fully controlled right at the place of the declaration. You can limit it as you wish:
public string Name { get; private set; }
This way you declare that "Name" can be modified only within the class itself, but can be read from outside.
So, what is missing from this language feature?
Initializer.
I may wish to initilize property to some non-default value. Like this:
public List<Person> Persons { get; private set; } = new List<Person>();
Read-only automatic property
In the example above, I don't actually need setter.
public List<Person> Persons { get; } = new List<Person>();
Obviously, you don't need read-only automatic property without initializer. Also note, that such property can never change its value, even in constructor, unlike readonly fields.
Attributes on generated fields
If you use simple event form and compiler generates field for storing delegate, you can apply attribute to the generated field by using attribute target:
[field: NonSerialized]
public event EventHandler Closed;
I wish I could do the same with automatic properties:
[field: NonSerialized]
public List<Person> Persons { get; } = new List<Person>();
Conclusion
Few simple improvements over existing implementation could make automatic properties much more useful in everyday professional .NET development. Unfortunately, language designers decided:
they would work in the "common case" which among other things means no attributes on the generated field. The idea behind that is keeping them simple and not slowly mutating them into full properties.
I'd prefer the advanced version, if I had a chance to choose.
07 September 2007
ReSharper 3.0.3 EAP and Solution-wide Error Analysis
The ReSharper team is actively working on next version with C# 3.0 support, but we are still fixing things for ReSharper 3.0 and even add new features!
Among with various bug-fixes, ReSharper 3.0.3 features "Global Error Analysis" feature that finds compilation errors in your solution on-the-fly. It was available in early ReSharper 3.0 EAP builds, but then we decided that it is not mature enough to put it into release. Now, we've improved it and are going to include it in ReSharper 3.0.3 update.
You can get ReSharper 3.0.3 EAP build at download page. Take a look at post about Early Access Program, if you want to learn more about participating.
To enable analysis of all errors in solution, double-click a red crossing lines symbol at the very right of the status bar and check the "Analyze errors in whole solution" checkbox. Note, that it is per-solution setting. It may take quite a while to analyze your solution for the first time (you can continue your work), but once the solution has been analyzed only those files that may be affected by the changes made are reanalyzed. Tool window with all errors in your solution can be opened using ReSharper | Windows | Errors in Solution menu command. Also, next/previous error command walks through all solution errors, if solution-wide error analysis is enabled.
We would like to hear from you about this feature! Do you like it or not? Does it work fine for you? Do you have any problems? You can leave comments to this post, or drop a message in our EAP newsgroup. Thanks in advance!
Among with various bug-fixes, ReSharper 3.0.3 features "Global Error Analysis" feature that finds compilation errors in your solution on-the-fly. It was available in early ReSharper 3.0 EAP builds, but then we decided that it is not mature enough to put it into release. Now, we've improved it and are going to include it in ReSharper 3.0.3 update.
You can get ReSharper 3.0.3 EAP build at download page. Take a look at post about Early Access Program, if you want to learn more about participating.
To enable analysis of all errors in solution, double-click a red crossing lines symbol at the very right of the status bar and check the "Analyze errors in whole solution" checkbox. Note, that it is per-solution setting. It may take quite a while to analyze your solution for the first time (you can continue your work), but once the solution has been analyzed only those files that may be affected by the changes made are reanalyzed. Tool window with all errors in your solution can be opened using ReSharper | Windows | Errors in Solution menu command. Also, next/previous error command walks through all solution errors, if solution-wide error analysis is enabled.
We would like to hear from you about this feature! Do you like it or not? Does it work fine for you? Do you have any problems? You can leave comments to this post, or drop a message in our EAP newsgroup. Thanks in advance!
06 September 2007
C# 3.0 Collection Initializers - Incomplete Feature?
I was really confused when I learned that "collection initializer" is so limited. I thought it was so natural to support extension methods for "Add" method, but it doesn't.
In short, collection initializer is the following syntax:
Each item in the braces is simply transformed to the call of Add method with appropriate signature.
It's a bit more complex in reality, but it doesn't matter here.
So, when I first saw description of the feature I thought: How cool! I can specify extension method "Add" for "StringBuilder" and get the following:
But, restrictions are too strong - type being constructed should implement IEnumerable and have instance method "Add". IEnumerable is not of a big deal, but inability to use extension methods for Add is deal breaker.
How about this?
No way. You can't use collection initializer for XmlDocument, because it doesn't have Add methods. It is IEnumerable, though.
May be this?
No way. PermissionSet is IEnumerable too, but does have AddPermission instead of Add method.
If it only were searching for candidates as follows:
This change, or something similar, would turn the otherwise very limited collection initializers into really powerfull object initialization feature.
In short, collection initializer is the following syntax:
var list = new List<int> { 1, 2, 3 };
var dic = new Dictionary<int,string> { { 1, "a" }, { 2, "b" }, { 3, "c" } };
Each item in the braces is simply transformed to the call of Add method with appropriate signature.
var list = new List<int>();
list.Add(1);
list.Add(2);
list.Add(3);
var dic = new Dictionary<int,string>();
dic.Add(1,"a");
dic.Add(2,"b");
dic.Add(3,"c");
It's a bit more complex in reality, but it doesn't matter here.
So, when I first saw description of the feature I thought: How cool! I can specify extension method "Add" for "StringBuilder" and get the following:
var sb = new StringBuilder { "Text = ", Text, ";", "Value = ", Value };
But, restrictions are too strong - type being constructed should implement IEnumerable and have instance method "Add". IEnumerable is not of a big deal, but inability to use extension methods for Add is deal breaker.
How about this?
XmlDocument doc = new XmlDocument
{
new Node("person") { Attributes = { { "name", "John" }, { "age", "42" } },
Nodes =
{
new Node("phones") { Nodes =
{
new Node("number") { Value = "123 45 678" },
new Node("number") { Value = "777 77 777" },
new Node("number") { Value = "987 65 432" }
}
}
}
No way. You can't use collection initializer for XmlDocument, because it doesn't have Add methods. It is IEnumerable, though.
May be this?
var set = new PermissionSet( new ZoneIdentityPermission(...), new PrincipalPermission(...) };
No way. PermissionSet is IEnumerable too, but does have AddPermission instead of Add method.
If it only were searching for candidates as follows:
- If type implements "IEnumerable", look for instance Add method with appropriate parameters,
- If not found, if type implements "IEnumerable", look for extension method Add with appropriate parameters,
- If not found, look for extension method AddToSequence with appropriate parameters.
This change, or something similar, would turn the otherwise very limited collection initializers into really powerfull object initialization feature.
04 September 2007
Visualize Right Margin in Visual Studio
ReSharper has formatting option to keep your source code lines below certain limit.
In Options, go to Languages / C# / Formatting Style / Line Breaks and Wrapping, find "Wrap long lines" below "Line Wrapping" group and enable it, then set "Right margin (columns)" to the desired value. That's pretty cool, but how can one see which lines will be wrapped?
Meet Visual Studio secret feature: Guides!
As described in this blog post, you can play a bit with registry and make Visual Studio display nice dotted vertical lines at specific column:
Now you will be able to see when your lines are too long, and probably make manual formatting before ReSharper will split lines at next reformat.
In Options, go to Languages / C# / Formatting Style / Line Breaks and Wrapping, find "Wrap long lines" below "Line Wrapping" group and enable it, then set "Right margin (columns)" to the desired value. That's pretty cool, but how can one see which lines will be wrapped?
Meet Visual Studio secret feature: Guides!
As described in this blog post, you can play a bit with registry and make Visual Studio display nice dotted vertical lines at specific column:
- Open "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor" key
- Create new string value "Guides"
- Set its value to something like "RGB(192,192,192) 119" (columns in registry are zero-based)
- Restart Visual Studio
Now you will be able to see when your lines are too long, and probably make manual formatting before ReSharper will split lines at next reformat.
30 August 2007
ReSharper vs C# 3.0 - Implicitly Typed Locals
Last month I was on vacation, living in the country, with no access to Internet, doing no programming, reading non-technical books, walking, swimming and otherwise enjoying my life, my family and the nature. It was really-really cool! However, I admit I was thinking a bit about ReSharper features for C# 3.0 and one of the things that puzzled me was
Obviously, developer have to use var keyword in case of anonymous types, and can't use var if local variable's type cannot be inferred at the declaration point. But most locals are suitable for both forms - explicit type and var keyword. Context action to switch from explicit type to var and back is okay, but we would like to analyse the code and suggest using var in cases where it will improve the code.
Some cases where it seems just fine to suggest var are:
However, various code styles may need to suggest in other cases. For example, programming in functional style with small methods can benefit from suggesting every suitable local variable to be converted to var style. Or may be your project has IElement root interface and you just know that every variable with "element" name is IElement and you don't want explicit types for this case. Probably, any method with the name GetTreeNode() always return ITreeNode and you want vars for all such local variable.
Currently, we have two suggestions: one that suggests every suitable explicitly typed local to be converted to implicityly typed var, and another that suggests according to rules above. They work fine within the team. I hope EAP will give us some feedback about how it works, but Early Access Program for ReSharper 4.0 will be opened later this year.
Meanwhile, do you have any ideas, suggestions or examples where you'd like to see suggestion to convert explicitly typed local variable to the var form?
To var or not to var?
Obviously, developer have to use var keyword in case of anonymous types, and can't use var if local variable's type cannot be inferred at the declaration point. But most locals are suitable for both forms - explicit type and var keyword. Context action to switch from explicit type to var and back is okay, but we would like to analyse the code and suggest using var in cases where it will improve the code.
Some cases where it seems just fine to suggest var are:
- New object creation expression: var dictionary = new Dictionary<int, string>();
- Cast expression: var element = (IElement)obj;
- Safe Cast expression: var element = obj as IElement;
- Generic method call with explicit type arguments, when return type is generic: var manager = serviceProvider.GetService<IManager>()
- Generic static method call or property with explicit type arguments, when return type is generic: var manager = Singleton<Manager>.Instance;
However, various code styles may need to suggest in other cases. For example, programming in functional style with small methods can benefit from suggesting every suitable local variable to be converted to var style. Or may be your project has IElement root interface and you just know that every variable with "element" name is IElement and you don't want explicit types for this case. Probably, any method with the name GetTreeNode() always return ITreeNode and you want vars for all such local variable.
Currently, we have two suggestions: one that suggests every suitable explicitly typed local to be converted to implicityly typed var, and another that suggests according to rules above. They work fine within the team. I hope EAP will give us some feedback about how it works, but Early Access Program for ReSharper 4.0 will be opened later this year.
Meanwhile, do you have any ideas, suggestions or examples where you'd like to see suggestion to convert explicitly typed local variable to the var form?
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:
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:
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.
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
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.
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:
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?
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.
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.
- Subscribe to newsgroup or bookmark forums. They are synchronized, so you can use whatever you like most.
- Read about creating requests in our JIRA database. Register in JIRA.
- Download and install ReSharper 3.0.2 nightly build.
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?
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:
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.
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.
29 June 2007
ReSharper Critical Update 3.0.1 is Out
As you've probably noticed, we had some nasty bugs which prevented some people from enjoying great new features of ReSharper 3.0. We addressed most of the critical issues in about a week and here is the result: ReSharper 3.0.1 which you can get on the official download page.
If you had problems with ASP.NET user controls, To-do Explorer, Unit Testing or any of these bugs -- you may want to give another try with ReSharper 3.0.1
If you had problems with ASP.NET user controls, To-do Explorer, Unit Testing or any of these bugs -- you may want to give another try with ReSharper 3.0.1
25 June 2007
ReSharper Curious Facts - Unit Testing
21 June 2007
ReSharper Curious Facts - Ancient Request
Oldest request fixed in ReSharper 3.0 is number 2235, the one about intellisense in app.config files, originally filed on May 06, 2004. Interesting, it was me who submitted it when I was not working at JetBrains but already loved ReSharper and used it in my daily work.
19 June 2007
ReSharper 3.0 for C# Developer
While I have a few spare minutes before reviewing another document being built for web site, marketing and such, I'd like to share brief list of new features in ReSharper 3.0 that will help C# developers to be even more productive. This list is not complete and doesn't go into details about ASP.NET support or XML and XAML features. Instead, these are core C# language productivity boosters that can be used immediately in any C# project.
Go to Symbol -- navigate to any type, field, method, property or event by its name. Of course, camels are here with their humps ready to save you some typing.
Go to next or previous error -- skip warnings and suggestions and put caret immediately on the red code.
Automatic type member layout -- sort and group fields, constructors, properties, inner types, members implementing interface and other members when your reformat code. You can specify custom code layouting patterns in options dialog.
Smart Completion -- smart-complete type arguments and type parameters, infer types and suggest applicable symbols. Also, a nice little helper to give the name to unnamed exception in catch block when smart-completing in place where Exception is expected.
Advanced type choosing -- in refactorings and other places where you have to enter type name ReSharper now provides experience similar to Go to Type.
Find symbols referenced in type or method -- useful for getting big picture about what is using inside a type or method, and drill-down to details in familiar Find Usages style.
Find dependent code -- an advanced version of former Find Module Usages command, which is capable of searching code depending on specific project throughout the solution. If you need to find how particular assembly reference is used (or not used), invoke it on reference in Solution Explorer.
Filter found usages of attributes -- attributes has two distinct categories of places where they are used. One is where they are applied to an entity and the other is where they are analysed via GetCustomAttributes() methods. If you work with attributes a lot, you will find new filter in Find Usages saving you a lot of browsing time.
Highlight usages of expression -- select expression and see where the same expression is used in a method or in a file.
Improved Type Hiearchy -- member preview pane for selected type and two new view modes for deep hierarchies. One mode shows instantiatable types of the hierarchy as roots and their bases as subnodes. The other shows leaf interfaces - those that have only classes as derived types.
Moving things around -- no need to copy/paste code in order to move statement few lines below, move out of "if" statement or push into "for" loop. Much like manual member reordering, which of course still works. Can reorder enum members, though it is not always safe - know what you are doing. Reorders parameters though not changing call sites - thus not a refactoring. Works in XML to reorder nodes too.
Generating equality -- when generating Equals & GetHashCode, you can now optionally generate equality and inequality operators, implement strongly typed IEquatable interface.
Improved Stack Trace Explorer -- now highlights types, methods and source code paths, deals better with broken stacktraces, works for localized stacktraces. Also doesn't show "paste" dialog - less one key to hit.
Generate from Solution Explorer -- hit Alt-Ins while you are on the folder, file or project in solution explorer and bring instant New File From Template menu. Combine with new Locate in Solution Explorer action to find your currently open file in Solution.
Unit Test Explorer -- browse all unit tests in solution, form arbitrary set of tests, multiple sessions with different sets (with simultaneous run!), better output presentation, and the foundation for more features in future versions.
To-do Explorer -- keeps an up-to-date list of comments matching specified patterns for the whole solution, like "TODO:", "BUG:" , "To John:", "Don't forget to remove it before release!" and so on. Processes comments in C#, VB.NET, XML, XAML and ASP.NET pages (both HTML and code).
XML support -- enables almost all editor enhancement in XML files, like expand/shrink selection, highlight and navigate to matching tag, move tags, split and join, replace tags and attributes. Provides type completion and can automatically insert assembly qualification to avoid annoying typing in files like app.config.
Custom string.Format methods -- tell ReSharper about your own format-like methods and get full featured analysis, context actions and quick fixes for them.
New code inspections -- more checks for redundancy, useful suggestions and warnings. Supports #pragma directives and project settings to suppress warnings.
New quick fixes and context actions -- less manual typing, more focus on your primary task. New quick fixes provide alternative ways to fix errors, remove redundancies and deal with type parameters and constaints. New context actions give you more power for ad-hoc code transformations.
So, these are highlights. Complete list will be available short after ReSharper 3.0 is released - either on official site or here, in my blog. There are many subtle changes and nice little additions that make up the product. I don't know some of them myself! But I strongly feel that ReSharper 3.0 is another step up to the ideal development environment.
Develop with pleasure!
Go to Symbol -- navigate to any type, field, method, property or event by its name. Of course, camels are here with their humps ready to save you some typing.
Go to next or previous error -- skip warnings and suggestions and put caret immediately on the red code.
Automatic type member layout -- sort and group fields, constructors, properties, inner types, members implementing interface and other members when your reformat code. You can specify custom code layouting patterns in options dialog.
Smart Completion -- smart-complete type arguments and type parameters, infer types and suggest applicable symbols. Also, a nice little helper to give the name to unnamed exception in catch block when smart-completing in place where Exception is expected.
Advanced type choosing -- in refactorings and other places where you have to enter type name ReSharper now provides experience similar to Go to Type.
Find symbols referenced in type or method -- useful for getting big picture about what is using inside a type or method, and drill-down to details in familiar Find Usages style.
Find dependent code -- an advanced version of former Find Module Usages command, which is capable of searching code depending on specific project throughout the solution. If you need to find how particular assembly reference is used (or not used), invoke it on reference in Solution Explorer.
Filter found usages of attributes -- attributes has two distinct categories of places where they are used. One is where they are applied to an entity and the other is where they are analysed via GetCustomAttributes() methods. If you work with attributes a lot, you will find new filter in Find Usages saving you a lot of browsing time.
Highlight usages of expression -- select expression and see where the same expression is used in a method or in a file.
Improved Type Hiearchy -- member preview pane for selected type and two new view modes for deep hierarchies. One mode shows instantiatable types of the hierarchy as roots and their bases as subnodes. The other shows leaf interfaces - those that have only classes as derived types.
Moving things around -- no need to copy/paste code in order to move statement few lines below, move out of "if" statement or push into "for" loop. Much like manual member reordering, which of course still works. Can reorder enum members, though it is not always safe - know what you are doing. Reorders parameters though not changing call sites - thus not a refactoring. Works in XML to reorder nodes too.
Generating equality -- when generating Equals & GetHashCode, you can now optionally generate equality and inequality operators, implement strongly typed IEquatable
Improved Stack Trace Explorer -- now highlights types, methods and source code paths, deals better with broken stacktraces, works for localized stacktraces. Also doesn't show "paste" dialog - less one key to hit.
Generate from Solution Explorer -- hit Alt-Ins while you are on the folder, file or project in solution explorer and bring instant New File From Template menu. Combine with new Locate in Solution Explorer action to find your currently open file in Solution.
Unit Test Explorer -- browse all unit tests in solution, form arbitrary set of tests, multiple sessions with different sets (with simultaneous run!), better output presentation, and the foundation for more features in future versions.
To-do Explorer -- keeps an up-to-date list of comments matching specified patterns for the whole solution, like "TODO:", "BUG:" , "To John:", "Don't forget to remove it before release!" and so on. Processes comments in C#, VB.NET, XML, XAML and ASP.NET pages (both HTML and code).
XML support -- enables almost all editor enhancement in XML files, like expand/shrink selection, highlight and navigate to matching tag, move tags, split and join, replace tags and attributes. Provides type completion and can automatically insert assembly qualification to avoid annoying typing in files like app.config.
Custom string.Format methods -- tell ReSharper about your own format-like methods and get full featured analysis, context actions and quick fixes for them.
New code inspections -- more checks for redundancy, useful suggestions and warnings. Supports #pragma directives and project settings to suppress warnings.
New quick fixes and context actions -- less manual typing, more focus on your primary task. New quick fixes provide alternative ways to fix errors, remove redundancies and deal with type parameters and constaints. New context actions give you more power for ad-hoc code transformations.
So, these are highlights. Complete list will be available short after ReSharper 3.0 is released - either on official site or here, in my blog. There are many subtle changes and nice little additions that make up the product. I don't know some of them myself! But I strongly feel that ReSharper 3.0 is another step up to the ideal development environment.
Develop with pleasure!
ReSharper 3.0 Release Candidate 2
I'd like to give our big THANKS to those brave people who tried out Beta, Beta2 or Release Candidate, provided invaluable feedback and revealed blocking problems in the upcoming ReSharper 3.0. We really appreciate your effort and doing our best to fix bugs and problems breaking your productivity and flow.
We have a new RC2 build published for you. I ask you to download and try the build.
We have a new RC2 build published for you. I ask you to download and try the build.
17 June 2007
ReSharper 3.0 Release Candidate
We are getting really close to ReSharper 3.0 release so we have a Release Candidate build published for you. It has LOTS of improvements over Beta2 particularly in language-specific editions. I recommend everyone to download the build. This might well be your last chance before relase to make sure it works perfectly for you.
Consequently, I will have more time for blogging next week, so if you have some particular topic in mind you would like me to write about -- drop me a comment.
Consequently, I will have more time for blogging next week, so if you have some particular topic in mind you would like me to write about -- drop me a comment.
16 June 2007
ReSharper 3.0 - Coming Soon
It's been quite a while since I wrote about ReSharper features, but there was a reason -- we are building final bits of ReSharper 3.0. We passed not-so-good Beta milestone, a much better Beta2 update and currently working on last changes for Release Candidate. If you didn't yet try ReSharper 3.0 pre-release builds -- download almost-release-quality Nightly Builds now and tell us what do you think!
Note: ReSharper 3.0 Visual Basic .NET edition has known problems with ASP.NET.
Note: ReSharper 3.0 Visual Basic .NET edition has known problems with ASP.NET.
23 May 2007
Jedi Way - Coding in Reverse
It looks like "ReSharper Jedi" term is beginning to spread! So here is ReSharper Jedi Code, converted from original Jedi Code:
ReSharper Jedi are the guardians of quality and productivity in the .NET world.
ReSharper Jedi use their powers to improve and advance source code, never to degrade.
ReSharper Jedi respect all developers, in any language, with any tools.
ReSharper Jedi serve others rather than ruling over them, for the good of the .NET world.
ReSharper Jedi seek to improve themselves through knowledge and training.
So what would be the major skill ReSharper Jedi should master? I think it is Coding in Reverse. This technique is widely used in test-driven development, I believe. However, it is so effective that every developer should master this skill regardless of programming style. Main principle could be described as follows:
1. Learn to like red code.
2. Always begin with expressing your goal.
3. Deredify your code.
There is one thing to dislike, though. Automatic completion as you type doesn't work well when there are undefined symbols. However it seems to be more about lack of support in tools than fundamental limitation of the technique.
Let's see how does it work.
Code in red indicates unresolved symbols which are just not there yet. At this point I can easily continue writing code for Main method and change my mind any time.
I've expressed my goal pretty well. See how I changed CommandLineParameter to ICommandLineParameter, when I decided that interface would be better. Also, I was able to use "foreach" Live Template to iterate over collection of undefined type.
Okay, now I have to deredify my code and create some methods and types. Where is my lightsaber bulb and powerful quick-fixes?
Now we need to fill methods with real code, and I will show how to use the Force by implementing ParseCommandLine. We again begin with typing our goal:
Several keystrokes, quick fixes, live templates, some typing and we get to another point:
I use the Force and create class which not only contains required constructor, but also implements interface!
I leave it as an exercise to finish the sample code for anyone who want to practice this technique. Implement ProcessParameter by using some ICommandLineParameter members before declaring them, then quick-fix your way into declaring them, then use Jedi skills and implement members on the SimpleParameter.
Have fun and may the Force be with you!
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
ReSharper Jedi are the guardians of quality and productivity in the .NET world.
ReSharper Jedi use their powers to improve and advance source code, never to degrade.
ReSharper Jedi respect all developers, in any language, with any tools.
ReSharper Jedi serve others rather than ruling over them, for the good of the .NET world.
ReSharper Jedi seek to improve themselves through knowledge and training.
So what would be the major skill ReSharper Jedi should master? I think it is Coding in Reverse. This technique is widely used in test-driven development, I believe. However, it is so effective that every developer should master this skill regardless of programming style. Main principle could be described as follows:
Use Before Declare.
1. Learn to like red code.
2. Always begin with expressing your goal.
3. Deredify your code.
There is one thing to dislike, though. Automatic completion as you type doesn't work well when there are undefined symbols. However it seems to be more about lack of support in tools than fundamental limitation of the technique.
Let's see how does it work.
Code in red indicates unresolved symbols which are just not there yet. At this point I can easily continue writing code for Main method and change my mind any time.
I've expressed my goal pretty well. See how I changed CommandLineParameter to ICommandLineParameter, when I decided that interface would be better. Also, I was able to use "foreach" Live Template to iterate over collection of undefined type.
Okay, now I have to deredify my code and create some methods and types. Where is my light
Now we need to fill methods with real code, and I will show how to use the Force by implementing ParseCommandLine. We again begin with typing our goal:
Several keystrokes, quick fixes, live templates, some typing and we get to another point:
I use the Force and create class which not only contains required constructor, but also implements interface!
I leave it as an exercise to finish the sample code for anyone who want to practice this technique. Implement ProcessParameter by using some ICommandLineParameter members before declaring them, then quick-fix your way into declaring them, then use Jedi skills and implement members on the SimpleParameter.
Have fun and may the Force be with you!
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
22 May 2007
Coding Session with ReSharper
ReSharper team is approaching Feature Freeze milestone for version 3.0, so I didn't have time to write thoughtful posts. However, I needed to write primitive utility for doing some batch operations on the file system structure recursively, and I decided to record a small screen cast for part of the real coding session. It is about 8 minutes long and shows many things I use daily during development. I hope you will enjoy the movie :)
Download "Jedi Coding" from ReSharper Demo page.
Quality is not very good to keep size small. Music in background is "Voodoo People" by Prodigy from "Music For The Jilted Generation" album, I only repeated ending so it fit movie time.
Note: Some or all of the features seen in this movie may be available only in latest EAP versions of ReSharper.
Download "Jedi Coding" from ReSharper Demo page.
Quality is not very good to keep size small. Music in background is "Voodoo People" by Prodigy from "Music For The Jilted Generation" album, I only repeated ending so it fit movie time.
Note: Some or all of the features seen in this movie may be available only in latest EAP versions of ReSharper.
08 May 2007
Code Completion with ReSharper
Completion with ReSharper is very different from what you have in Visual Studio. Some people refer to it as "broken". Indeed, when you start using ReSharper's intellisense, you may feel that something is "wrong". But it's just a little different and much better. I will describe completion features in ReSharper and you'll see how superior they are to what Visual Studio offers.
Look
Visually, completion list is not that different with default ReSharper settings. Here is original Visual Studio completion for type System.String, without any prefix:
Here is what ReSharper displays:
First evident difference is usage of bold font face. It emphasizes immediate members of type, those declared exactly in type for which completion was called. Note how GetType() is not bold, because it was inherited from System.Object. In large hierarchies, like windows controls, it is huge timesaver to be able to spot members specific to current type.
Another obvious difference is ability to show all overloads for a member in a signature popup, not just some random one with cryptic message (+2 overload(s)). You can instantly see that you can test end of line against string in a case-insensitive way and that it would be second boolean parameter.
You can also see, that ReSharper can suggest indexer (and correctly remove dot when inserting brackets). We also have some custom icons for parameters and local variables to distinguish them from fields.
If you wish, you can set completion font to match font in Editor and thus align completion items with what you type. You can tweak it on ReSharper/Options/IntelliSense/Code Completion page.
Narrow Down
More differences become visible when you start typing while completion list is open.
As you can see, list has become smaller and contains only items with the specified prefix, which is highlighted. For a large completion list, such as when you have windows control, it helps you quickly find what you need. It is even more important for type completion, but later about it.
Replace and Insert
The most confusing part and most difficult thing to adopt in ReSharper completion behavior is choosing between replacing and inserting. When you write new code, it doesn't matter, but if you are using completion inside existing expression it makes big difference. Consider the following example: we have method that replaces all spaces with underscores. Imagine that you need to modify the body to remove leading and trailing spaces before doing replacement.
You position caret right after "text." and hit Ctrl-Space, then type few letters to locate Trim method.
Now, if you hit "Tab" key to complete the identifier it will remove "Replace" and insert "Trim", then put caret into parenthesis. Very useful when you need to change existing identifier to another one. Note the light red highlighting which denotes text to be removed, if you hit Tab. If you hit "Enter" key, it will just insert "Trim()" and let you specify parameters, if needed.
Name Suggestion
One more thing that ReSharper does for you is suggesting variable names when typing declaration.
It works for fields, parameters, variables, members and alike. Saves a lot of typing, I have to say. Name suggestion completion takes naming conventions into account, so be sure to set them in ReSharper/Options/Code Style/ C# or Visual Basic / Naming Convention.
Type Completion
Whenever you need a type at the caret position and you only have basic completion at hands, you have to type full type name and then import type via some sort of fix, e.g. Visual Studio smart-tag action. You also have to match case, and can you remember which one is right - DESCryptoServiceProvider or DesCryptoServiceProvider?
ReSharper comes to rescue with Type Completion, which shows all types matching prefix regardless of (un-)imported namespaces and inserts required using directives when you select a type.
Default shortcut is Ctrl-Alt-Space. Start using it now!
Smart Completion
ReSharper has deep knowledge about your code. Really! When you see variable declaration in gray, it is ReSharper who analysed execution flow and figured out that particular variable is not used. Some of this knowledge is available to you in completion. When it is known what type is expected at specific point, you may get filtered list of available symbols by invoking Smart Complete (default shortcut Ctrl-Shift-Space):
You can see that ReSharper suggested some static members of System.String and parameter "text". Well, you were going to return something of string type, so here you are!
Smart Completion is also smart enough to suggest anonymous and regular method creation:
Or even local variable creation in place of out parameter:
Conclusion
When you type code, completion is your best friend. Master all three completion kinds, practice for second-nature and you can achieve marvellous code generation speed.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
Look
Visually, completion list is not that different with default ReSharper settings. Here is original Visual Studio completion for type System.String, without any prefix:
Here is what ReSharper displays:
First evident difference is usage of bold font face. It emphasizes immediate members of type, those declared exactly in type for which completion was called. Note how GetType() is not bold, because it was inherited from System.Object. In large hierarchies, like windows controls, it is huge timesaver to be able to spot members specific to current type.
Another obvious difference is ability to show all overloads for a member in a signature popup, not just some random one with cryptic message (+2 overload(s)). You can instantly see that you can test end of line against string in a case-insensitive way and that it would be second boolean parameter.
You can also see, that ReSharper can suggest indexer (and correctly remove dot when inserting brackets). We also have some custom icons for parameters and local variables to distinguish them from fields.
If you wish, you can set completion font to match font in Editor and thus align completion items with what you type. You can tweak it on ReSharper/Options/IntelliSense/Code Completion page.
Narrow Down
More differences become visible when you start typing while completion list is open.
As you can see, list has become smaller and contains only items with the specified prefix, which is highlighted. For a large completion list, such as when you have windows control, it helps you quickly find what you need. It is even more important for type completion, but later about it.
Replace and Insert
The most confusing part and most difficult thing to adopt in ReSharper completion behavior is choosing between replacing and inserting. When you write new code, it doesn't matter, but if you are using completion inside existing expression it makes big difference. Consider the following example: we have method that replaces all spaces with underscores. Imagine that you need to modify the body to remove leading and trailing spaces before doing replacement.
public string QuoteSpaces(string text)
{
return text.Replace(' ', '_');
}
You position caret right after "text." and hit Ctrl-Space, then type few letters to locate Trim method.
Now, if you hit "Tab" key to complete the identifier it will remove "Replace" and insert "Trim", then put caret into parenthesis. Very useful when you need to change existing identifier to another one. Note the light red highlighting which denotes text to be removed, if you hit Tab. If you hit "Enter" key, it will just insert "Trim()" and let you specify parameters, if needed.
Name Suggestion
One more thing that ReSharper does for you is suggesting variable names when typing declaration.
It works for fields, parameters, variables, members and alike. Saves a lot of typing, I have to say. Name suggestion completion takes naming conventions into account, so be sure to set them in ReSharper/Options/Code Style/ C# or Visual Basic / Naming Convention.
Type Completion
Whenever you need a type at the caret position and you only have basic completion at hands, you have to type full type name and then import type via some sort of fix, e.g. Visual Studio smart-tag action. You also have to match case, and can you remember which one is right - DESCryptoServiceProvider or DesCryptoServiceProvider?
ReSharper comes to rescue with Type Completion, which shows all types matching prefix regardless of (un-)imported namespaces and inserts required using directives when you select a type.
Default shortcut is Ctrl-Alt-Space. Start using it now!
Smart Completion
ReSharper has deep knowledge about your code. Really! When you see variable declaration in gray, it is ReSharper who analysed execution flow and figured out that particular variable is not used. Some of this knowledge is available to you in completion. When it is known what type is expected at specific point, you may get filtered list of available symbols by invoking Smart Complete (default shortcut Ctrl-Shift-Space):
You can see that ReSharper suggested some static members of System.String and parameter "text". Well, you were going to return something of string type, so here you are!
Smart Completion is also smart enough to suggest anonymous and regular method creation:
Or even local variable creation in place of out parameter:
Conclusion
When you type code, completion is your best friend. Master all three completion kinds, practice for second-nature and you can achieve marvellous code generation speed.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
30 April 2007
Format Strings -- Episode Two
Last time I wrote about using string.Format as you type. What if you already have some code and want to transform it to string.Format?
When you position caret inside such string expression, ReSharper displays light bulb and suggests few context actions (caret was on myPath in this case):
It is not surprizing that the first item in menu does what we want:
If there is known method overload that fits format style, it will be used instead of creating extra string.Format call:
ReSharper converts it to:
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
public override string ToString()
{
return "Folder: '" + myPath + "'";
}
When you position caret inside such string expression, ReSharper displays light bulb and suggests few context actions (caret was on myPath in this case):
It is not surprizing that the first item in menu does what we want:
public override string ToString()
{
return string.Format("Folder: '{0}'", myPath);
}
If there is known method overload that fits format style, it will be used instead of creating extra string.Format call:
public void Write(StreamWriter writer)
{
writer.Write("Folder: '" + myPath + "'");
}
ReSharper converts it to:
public void Write(StreamWriter writer)
{
writer.Write("Folder: '{0}'", myPath);
}
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
27 April 2007
Transforming Conditionals
Testing conditions is at least 50% of code in a typical program. When developer writes code, he not always knows in advance how method will look like at the end. Let's look at some typical cases.
This one is pretty simple method, which takes care of null object:
Then I decided to add special handling for IConvertible:
Now it seems that it would have been better idea to check and return null immediately instead of placing all the code in the block. How can we fix this? I put caret on an "if" keyword and hit Alt-Enter.
After context action is executed I get what I need:
If you like shorter methods, you can further transform the code:
Accepting convertion to conditional makes it even smaller:
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
This one is pretty simple method, which takes care of null object:
public string ConvertToString(object obj)
{
if (obj != null)
return obj.ToString();
return null;
}
Then I decided to add special handling for IConvertible:
public string ConvertToString(object obj)
{
if (obj != null)
{
IConvertible convertible = obj as IConvertible;
if (convertible != null)
return Convert.ToString(convertible);
return obj.ToString();
}
return null;
}
Now it seems that it would have been better idea to check and return null immediately instead of placing all the code in the block. How can we fix this? I put caret on an "if" keyword and hit Alt-Enter.
After context action is executed I get what I need:
public string ConvertToString(object obj)
{
if (obj == null)
return null;
IConvertible convertible = obj as IConvertible;
if (convertible != null)
return Convert.ToString(convertible);
return obj.ToString();
}
If you like shorter methods, you can further transform the code:
Accepting convertion to conditional makes it even smaller:
public string ConvertToString(object obj)
{
if (obj == null)
return null;
IConvertible convertible = obj as IConvertible;
return convertible != null ? Convert.ToString(convertible) : obj.ToString();
}
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
Highlight Usages Of What?
Many people know about Find Usages (default shortcut Alt-F7), which find usages of element under caret. Some people known about Highlight Usages (default shortcut Ctrl-Shift-F7), which places highlighting markers in current file on element usages. However, ReSharper can highlight usages of different things as well.
Usages of Namespaces
Position caret on "using" directive (Imports in Visual Basic) and invoke Highlight Usages command. ReSharper will highlight all symbols which depend on namespace in question.
Usages of Expressions
Select expression in code and invoke Highlight Usages command. ReSharper will highlight same expressions in other places in code.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
Usages of Namespaces
Position caret on "using" directive (Imports in Visual Basic) and invoke Highlight Usages command. ReSharper will highlight all symbols which depend on namespace in question.
Usages of Expressions
Select expression in code and invoke Highlight Usages command. ReSharper will highlight same expressions in other places in code.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
24 April 2007
Jedi Way -- Implementing Members
Object-oriented program is easy to read, if written properly. At every point you deal with appropriate level of abstractness and you don't have to deal with implementation specific details most of the time. However, when you have large type hierarchies and you are going to modify some aspect of a top level interface -- you may be in trouble. You have to thoroughly investigate all implementing types and provide method body for each one. ReSharper can help, of course.
Jedi Trick Level 1
Invoke Type Hierarchy and select Derived Types in the toolbar. You will see hierarchy of types derived from the interface. Use "Go To Next/Previous Occurence" command (Ctrl-Alt-Down/Up) to navigate between types. As soon as you have type which requires implementation in the code editor, Code Analysis will show red squiggly. Invoke Quick Fix to implement member and type in method body.
Jedi Trick Level 2
Use Context Action's power to implement members. Position caret on the newely created member, IsAvailable in this case. You will see the lightsaber bulb which is activated with Alt-Enter. Select "Implement member" and you will be prompted with the list of types. You can select "All above types" and get method body throwing NotImplementedException for every type.
Jedi Trick Level 3
Use Quick Fix power to implement members. Type in method body right in the interface, as if it were implementation. Code Analysis will show red squiggly, because interface member cannot have body. But you will also get two Quick Fixes via red light bulb - remove method body or use body for implementations. As soon as you select second one, body will be copied to appropriate implementations and removed from interface.
Jedi Trick Level 1
Invoke Type Hierarchy and select Derived Types in the toolbar. You will see hierarchy of types derived from the interface. Use "Go To Next/Previous Occurence" command (Ctrl-Alt-Down/Up) to navigate between types. As soon as you have type which requires implementation in the code editor, Code Analysis will show red squiggly. Invoke Quick Fix to implement member and type in method body.
Jedi Trick Level 2
Use Context Action's power to implement members. Position caret on the newely created member, IsAvailable in this case. You will see the light
Jedi Trick Level 3
Use Quick Fix power to implement members. Type in method body right in the interface, as if it were implementation. Code Analysis will show red squiggly, because interface member cannot have body. But you will also get two Quick Fixes via red light bulb - remove method body or use body for implementations. As soon as you select second one, body will be copied to appropriate implementations and removed from interface.
Jedi Trick Level 4
Available to Yoda only.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
Format Strings -- Episode One
Are you going to override ToString? You do this from time to time, definitely.
You begin typing format string and immediately see ReSharper coming to rescue in an absolutely non-invasive way. First the light bulb will appear.
Second, you hit Alt-Enter to see the list of available context actions. Only one is available here, but it is exactly the one we need.
Accept it with Enter and you can start typing arguments.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
You begin typing format string and immediately see ReSharper coming to rescue in an absolutely non-invasive way. First the light bulb will appear.
Second, you hit Alt-Enter to see the list of available context actions. Only one is available here, but it is exactly the one we need.
Accept it with Enter and you can start typing arguments.
Note: Some or all of the features mentioned in this article may be available only in latest EAP versions of ReSharper.
Customizing ReSharper Colors
Sometimes people complain that they don't like ReSharper's colors, or default colors do not math their personal scheme, or identifier highlighting gets too much in the way. Luckily, you can configure colors.
Color configuration for ReSharper items can be changed in the Visual Studio Options (Tools Options menu), in the Fonts and Colors section. Select "Text Editor" in the settings combobox and scroll down to "Resharper" items. You will see color and font settings for identifiers of different kinds, error and warning highlighting, navigation targets, read/write usages and much more.
Color configuration for ReSharper items can be changed in the Visual Studio Options (Tools Options menu), in the Fonts and Colors section. Select "Text Editor" in the settings combobox and scroll down to "Resharper" items. You will see color and font settings for identifiers of different kinds, error and warning highlighting, navigation targets, read/write usages and much more.
20 April 2007
The Horizon Comes Closer
It's been a while since I last wrote about ReSharper future. That's because we are actively working on ReSharper 3.0, the upcoming new version of our intelligent Visual Studio add-in. Besides numerous bug fixes, improvements and greater performance, we are adding more functionality to our product. In the upcoming posts I'm going to reveal what is going to be included in ReSharper 3.0 in more detail. Now I'll just list the most important things we are planning for this release:
Visual Basic .NET
C# developers already know how fast one can work with source code when ReSharper is installed. Now we bring the same pleasure to VB.NET developers. Editor improvements, such as expand/collapse selection, navigate next/prev member, duplicate line, comment/uncomment block/line and other small features, make code editing more enjoyable. Completion brings Smart Completion and Type Completion flavors to VB.NET along with automatic Imports inserting and all other bells and whistles. Code generation with Alt-Ins provides a quick means for generating properties, constructors, overriding and implementing members and works with the same level of cleverness as it does in C#. Live Templates now understand VB.NET and have smart iteration and cast templates, such as For Each or TryCast. Of course, we have Refactoring support for VB.NET in this version, which includes the most important refactorings like Rename, Move and Copy Type, Change Signature, Introduct and Inline Variable, and many others.
If you are a VB.NET developer and if you've ever seen how fast ReSharper-powered C# developers work, you owe yourself to try our EAP versions of ReSharper 3.0.
XML support
We are adding a number of useful editor improvements to Visual Studio XML support. They include expand selection, navigate to next/previous tag, replace tags, and some others. Live Templates are now supported in XML files and have some useful macros. Type completion works in XML, so that you can write configuration files easier. You can also navigate to type from XML.
XAML support
Being a language for user interface definition, it is still a compilation unit and it defines types and fields which are visible from other code. ReSharper is now capable of parsing XAML files, navigating, searching, and otherwise providing data for code exploration tools. We also plan to support smart completion and type completion in specific places, like event handlers, namespace aliases and tags/attributes where a control type is expected. Refactoring support in XAML will be limited in this version, but will allow renaming and moving types between namespaces without breaking code.
Tools
Besides all the languages support listed above, we are adding a number of useful tools and upgrading some existing tools. We've included To-do Explorer, which hunts for comments according to specified patterns and displays them in a dedicated tool window for quick access. We've improved Type Hierarchy to show members of selected type, either all or just polymorphic, and added some new hierarchy browsing capabilities. Unit Testing system is undergoing a major update to support multiple sessions, better support for various testing frameworks like mbUnit, VSTS and NSpecify, improved debugging usability and allow browsing solution for tests in dedicated Unit Test Explorer tool window. The "Go to by name" family of features, which already includes Go To Type, File or File member, is supplemented with Go To Symbol - your best friend when you remember a method's name, but not that util class it was seen in.
Improvements and bug fixes
I'm not going to give you a list of hundreds of bugs and exceptions fixed since previous release. I can't even remember all those small improvements here and there, which makes development with ReSharper even smoother and helps support development flow. Numerous context actions help craft code faster in many new use cases. New code analysis helps keep code clean and spot various problems as soon as you create them (accidentaly, of course). New quick fixes provide yet more automatic code corrections.
What next?
I'm going to blog in details about some of the new features in ReSharper 3.0 and show you some screen casts. I will probably break announced rules of this blog and start publishing tips and tricks, combos and advanced techniques in code generation, analysis and refactoring.
Stay tuned!
Visual Basic .NET
C# developers already know how fast one can work with source code when ReSharper is installed. Now we bring the same pleasure to VB.NET developers. Editor improvements, such as expand/collapse selection, navigate next/prev member, duplicate line, comment/uncomment block/line and other small features, make code editing more enjoyable. Completion brings Smart Completion and Type Completion flavors to VB.NET along with automatic Imports inserting and all other bells and whistles. Code generation with Alt-Ins provides a quick means for generating properties, constructors, overriding and implementing members and works with the same level of cleverness as it does in C#. Live Templates now understand VB.NET and have smart iteration and cast templates, such as For Each or TryCast. Of course, we have Refactoring support for VB.NET in this version, which includes the most important refactorings like Rename, Move and Copy Type, Change Signature, Introduct and Inline Variable, and many others.
If you are a VB.NET developer and if you've ever seen how fast ReSharper-powered C# developers work, you owe yourself to try our EAP versions of ReSharper 3.0.
XML support
We are adding a number of useful editor improvements to Visual Studio XML support. They include expand selection, navigate to next/previous tag, replace tags, and some others. Live Templates are now supported in XML files and have some useful macros. Type completion works in XML, so that you can write configuration files easier. You can also navigate to type from XML.
XAML support
Being a language for user interface definition, it is still a compilation unit and it defines types and fields which are visible from other code. ReSharper is now capable of parsing XAML files, navigating, searching, and otherwise providing data for code exploration tools. We also plan to support smart completion and type completion in specific places, like event handlers, namespace aliases and tags/attributes where a control type is expected. Refactoring support in XAML will be limited in this version, but will allow renaming and moving types between namespaces without breaking code.
Tools
Besides all the languages support listed above, we are adding a number of useful tools and upgrading some existing tools. We've included To-do Explorer, which hunts for comments according to specified patterns and displays them in a dedicated tool window for quick access. We've improved Type Hierarchy to show members of selected type, either all or just polymorphic, and added some new hierarchy browsing capabilities. Unit Testing system is undergoing a major update to support multiple sessions, better support for various testing frameworks like mbUnit, VSTS and NSpecify, improved debugging usability and allow browsing solution for tests in dedicated Unit Test Explorer tool window. The "Go to by name" family of features, which already includes Go To Type, File or File member, is supplemented with Go To Symbol - your best friend when you remember a method's name, but not that util class it was seen in.
Improvements and bug fixes
I'm not going to give you a list of hundreds of bugs and exceptions fixed since previous release. I can't even remember all those small improvements here and there, which makes development with ReSharper even smoother and helps support development flow. Numerous context actions help craft code faster in many new use cases. New code analysis helps keep code clean and spot various problems as soon as you create them (accidentaly, of course). New quick fixes provide yet more automatic code corrections.
What next?
I'm going to blog in details about some of the new features in ReSharper 3.0 and show you some screen casts. I will probably break announced rules of this blog and start publishing tips and tricks, combos and advanced techniques in code generation, analysis and refactoring.
Stay tuned!
Subscribe to:
Posts (Atom)