This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: VS2005 beta refactorings - under-impressed
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
The VisualStudio 2005 beta available from Microsoft proudly lists Refactorings in its list of new features. I installed it and I've been playing with it for a while. Maybe I'm spoiled by the Smalltalk Refactoring Browser, but I'm not impressed by the refactorings in .NET
First, the refactorings included are
Extract Method
Rename
Encapsulate Field (equivalent to Abstract)
Extract Interface
Promote Local Variable to Parameter
Remove Parameters
Reorder Parameters
Where are the rest of the refactorings?
Extract to Temporary
Push up
Push down
Extract to Component
Inline Method
Inline all self sends
Create subclass
Convert to sibling
Protect
I suppose it's a good start, but I for one am used to having a whole lot more refactorings at my disposal. Maybe we'll get more in the next version.
All the refactoring menu items are enabled all the time. This means that you don't know that the refactoring is inappropriate for the selected code until you try the menu item and it fails. This is just annoying.
The extract method refactoring doesn't seem to be smart enough to detect that there already exists a method that does the same job. This is a very handy feature of the Smalltalk Refactoring browser.
The cardinal rule of a refactoring is that it musn't change existing functionality. With only a little work, I was able to make VS2005 refactoring break this rule. This one hole completely destroys my confidence in the tool. (I understand that I'm working with a beta, but I hope they fix it before the final release).
The code that broke the refactoring is:
public class Class1
{
protected int var1 = 0;
public virtual int Test2()
{
return Test() * 5;
}
public virtual int Test()
{
return var1 + 2;
}
}
public class Class2 : Class1
{
public override int Test()
{
int var1 = 5;
return var1 * 10;
}
When you run Test2, it returns 10. I selected the variable var1 in the Test method of Class2 and selected "Promote temporary to Parameter". Here's the result:
public class Class1
{
protected int var1 = 0;
public virtual int Test2()
{
return Test(5) * 5;
}
public virtual int Test(int var1)
{
return var1 + 2;
}
}
public class Class2 : Class1
{
public override int Test(int var1)
{
return var1 * 10;
}
Now when you run Test2, it returns 35. In my mind, the Test method in the superclass doesn't work the way it did before.
So it seems that these refactorings aren't complete, and aren't even correct. That's not a good sign.