Refactoring support in VB.NET

Anand and Tom ask whether VB.NET is going to have refactoring support in Whidbey. The short answer is, despite what the PDC lab person told Tom, “yes.” However, the long answer is, well, a bit longer than that.

What C# is calling “refactoring” is actually a collection of related-but-separate code manipulation features in the IDE. Things that are included under this rubric are, I believe:

  • Symbolic rename
  • Extract method
  • Extract interface
  • Encapsulate field
  • Reorder parameters
  • Remove parameter
  • Add parameter
  • Promote local to parameter

Some of these features are already slated to be included in the VB.NET Whidbey release, such as symbolic rename, and for others we’re open customer feedback as to which ones above they think are important. Or if there are ones you don’t see there, we want to hear about them as well! If you leave comments on this entry, I’ll make sure they get forwarded to Jay, the PM in charge of this area. (The more specific you are, the better. “Do everything that C# is doing.” is helpful, but “Reorder parameters is the most important to me because blah, blah, blah.” helps us even more!)

One thing that is likely, however, is that VB.NET won’t be using the term “refactoring” in the IDE to refer to these features. While that term is fairly common in some quarters, we believe there are lots of VB programmers who are likely to see a menu item called “Refactor” and just ignore it because they don’t know what the term means. We’d like to surface the features more directly so that they don’t get missed by our users. (If you disagree, feel free to give us a holler on that too!)

89 thoughts on “Refactoring support in VB.NET

  1. Roy Osherove

    For good refactoring options, look no further than the latest version of IntelliJ IDEA. There are some amazing things there to look at. Please, just play with it and you’ll see what I mean. As a .net developer, this is what I want my IDE to be like, refactoring wise.

    second, I disagree that "Refactoring" should be the name. If a VB developer does not know what refactoring means (and I’m a VB6 turned vb.net/c# developer) he should learn what is is and use it. Just like they have to learn what implementation inheritance means and what multi threaded GUI interfaces mean. It’s part of the new vocabulary, and it should not treat the VB developer as a second rate "I don’t understand complicated words" citizen.

    *Phew* ๐Ÿ™‚

    Reply
  2. Roy Osherove

    I disagree that "Refactoring" should be the name
    ->
    I disagree that "Refactoring" should *not* be the name
    ->
    meaning
    refactoring should be the name VB developers see IMHO

    sorry ๐Ÿ™‚

    Reply
  3. Corrado Cavalli

    Really glad to read this, in fact during Amanda’s session (no blogs from her yet?) I’ve eard something about it.
    I disagree with you about naming, VB users must have the same treatment as C# so, name it "refactoring" and spend some time (otherwise we’ll do for you in communities) explaining what the term means, but don’t force us (as C# plus VB.NET DEVs always remember both terms)

    Reply
  4. David Williams

    I find that there are two forms of refactoring that I do multiple times a day: Extract Method and Promote Local to Parameter. I think that in the long run, while I do Promote Local to Parameter more often (I write the local then promote immediately), but Extract Method is more useful as I tend to design monolithicaly then break into methods.

    Reply
  5. Mike Blumenthal

    I mainly do maintenance programming rather than new build, and I do a LOt of Extract Method and the parameter changes (add, remove, promote). I guess this may be because so much VB work (mine at least) is done to create a quick and inexpensive solution to an immediate business problem, and then extended to cover a broader range of use cases if this proves necessary. Any chance of Change Parameter Datatype (e.g. from integer to double, XMLDocument to XPATHDocument)?

    As for naming, from VB/Access Form design, right-click/Change To is a familar way of describing a similar feature. So – Change To – function, change to – parameter, change to – If Block, change to – For Loop and so on might feel nicely familiar. If feeling nicely familiar is what you’re after. Personally I’m happy with ‘refactor’ .

    Reply
  6. Dave Rothgery

    Incidentally, a bit of that old Access magic would be handy in the ASP.NET forms designer. Button <-> LinkButton <-> ImageButton changes and RadioButtonList<->DropDownList (and maybe <->CheckBoxList) changes should be possible without flipping to HTML view.

    Reply
  7. Tom Mertens

    I fully agree with Roy and with most others on the "Refactoring" stuff. VB.NET is not a kiddy language, so don’t treat all VB developers as kids but as real developers. If you want people to start taking VB.NET as a serious development language (which it actually is), please use the same naming as in other serious development tools and IDEs, i.e. Refactor. Please, do not "overprotect" VB developers.

    About which refactoring topics I already used most while experimenting with C#: extract method, extract interface, rename field/method, encapsulate field. These things would have been very useful to me when I had to take over and fix other developers’ code. Probably there will have been other features too, but I didn’t try them all currently.

    Reply
  8. AsbjornM

    Is there an belief that VB programmers are stupid? :), Call it Refactor, instead of some toy’ish name. Also we should get equally the same treatment in the refactoring scene that C# programmers get..

    Reply
  9. Pingback: Tom's corner

  10. Diego Vega

    Paul,

    I am willing to know which name the team will chose for these tools. However, unless it is something really better, I see no reason not to stick to "refactor". Any well informed VB.NET developer should know what it means. Otherwise, well, we know with knowledge comes power. I think it is perfectly natural to expect that some will disregard this feature at first as many are disregarding things like inheritance right now.

    I my opinion most refactoring concepts are language agnostic, and there exist some projects in which multiple languages are involved. So, maintaining some consistence among all the .NET languages could have some value.

    Regarding the importance of each feature, I have zero knowledge of refactoring academics, but I have had experience doing refactoring of some ugly VB code, both mine, and other people’s code I had to take over.

    I am listing the refactoring tasks I usually perform manually in order of importance for me. I know some things are to complex to automate but any help in those would be great:

    0. A customizable code beautifier: I know this is not in the list, but I usually need it before I start any refactoring work, specially if it is other people code.

    1. To infer a super class and maybe build a factory pattern from similar classes that were created by copying and pasting: This is probably one of the difficult tasks to automate, but it is usually one of the most time consuming and rewarding in my experience. In Visual Basic it must be very common, because the lack of inheritance in previous versions forced developers to copy and paste a lot. The output of this operation is usually cleaer, more debuggable and more extensible code, hopefully less bugs and fewer places to look for them. The main risk of doing this without any help is that the littlest oversight can lead to introducing unexpected behavior. How could the IDE help? I think it could include a side by side source comparison tool. I usually work with Beyond Compare which is superb.

    2. Move member to other class: Useful when you find that most of the members a method is accessing belong to a different class. I often end up realizing that the method also belongs "semantically" to the target class. Usually, when I finish moving all methods to the appropriate class, I evaluate the remaining public members for a chance to private scope. The expected output is better encapsulation, and usually shorter code. This works likewise with methods, properties and fields.

    3. Changing ADO Recordsets opened for sequential access to ADO.NET DataReaders in the middle tier. I know this one qualifies as a migration task, but I wonder if you could come up with a simple tool that does this. I have found this to be very time consuming, too complex for a simple search and replace, but too stupid to waste programmer hours in it.

    4. Switching from “On Error” to structured exception handling: I am not sure how easy it is to map those things, and I know “On Error” is still valid. But using try – catch blocks is so cleaner! I usually do this manually and it can be time consuming.

    5. Wrap “this” with try – catch block. Well, this one is not strictly refactoring, but it is related to 4.

    6. Encapsulate field.

    7. Symbolic renaming: This is important, but I think a simple search & replace will cut it 70% of the time.

    8. Change method signature.

    9. Global type replace: This may sound stupid but this can be useful when you decide to replace all instances of class A with instances of class B. A tool could analyze which members of class A are being accessed and offer a screen to map them to members of object B. The rest could be accomplished manually.

    10. Extract method.

    11. Inline method: opposite of extract method, useful when you find the method is used many times but only from a few places and you can’t find a good name for it ;)… I mean, you realize that having it separated is not clarifying but obfuscating the code.

    12. Replace multiple calls to invariant function with temp.

    By the way, I like the idea of having “Change to”.

    Reply
  11. Michael

    My two favorite features of IntelliJ IDEA are not refactorings per se. They are automatic code validation (a UI element turns green if the class will compile, yellow if there will be warning(s), red if it will not compile) and automatic detection of unused variables. Code that will cause a warning is underlined yellow, code that will break a compile is underlined red, and unused/unreachable code is underlined gray. This stuff took IntelliJ guys some time to get right but it is the thing I miss MOST in the .NET world.

    -Michael

    Reply
  12. julie lerman

    Christ Paul! Call it "refactoring"!!! You are giving the world more and more excuses to assume that VB developers are complete idiots and since you ARE a VB man, you wouldn’t really want that would you? It should be the same name in VB as it is in C#.

    Reply
  13. Douglas Reilly

    If folks want VB programmers taken seriously, you need to treat them like grownups, and use the same terms that other programmers use for well defined processes. Dumbing down the VB IDE does no one any favors.

    Reply
  14. Dave Rothgery

    I have to agree on keeping it "refactoring". The term isn’t all that opaque, and there’s not an obvious replacement term that would make more sense.

    But I don’t want to endorse copying C/C#/Java terminology without thinking about it. Otherwise we’d be stuck with lame, meaningless keywords like abstract and virtual. It’s bad enough that someone managed to sneak in C-speak for bit shifting operators and curly braces for array initializers.

    Reply
  15. Travis Laborde

    I agree with two things said above:

    1) Keep the name "refactoring"

    2) wrap "this" with a try catch block ๐Ÿ™‚ – Too many times you review someone else’s code and need to do this, and it’s annoying the way it works now.

    Reply
  16. Tony Pino

    My thoughts:

    1) Definetely call it "refactoring" – I see no reason to come up with another name.
    2) "Extract method", "wrap ‘this’ with a try catch block" and "symbolic rename" would be great. Also, a "change type" would be neat – with options being similar types (i.e "int32 to int64")

    Reply
  17. Anonymous

    The Refactoring support in Whidbey isn’t much, I’m really disappointed. I hope they will fix it until the release. So what’s wrong with it? For starters its only a disappointing few(I admit they do save work) but there has to be a lot more. Check out other Refactoring products. IntelliJ IDEA, Refactory. Hope fully this is just a taste of what’s to come in VS. How is the model, are they working with CodeDom? If they are, the support can be in more languages than C#/VB.Net. If not using the CodeDom why?. Can we use the API to implement more refactorings in our own addins?

    And yes the name should be refactoring, anything else would be absurd.

    Regards

    Reply
  18. Nikolaj Winnes

    Refcatoring should definitely be included in VB as well. Some of us devlop in both C# and VB, and I would hate to miss refactoring support in VB. Also let’s call it refactoring – the term is established, no need for another TLA ๐Ÿ™‚

    Reply
  19. Bill Evjen

    I would be rather disappointed if it had another name other than "Refactoring". VB developers are smart enough to accept 4-syllable words and not just glance over them.

    Reply
  20. Bill

    What a slam.
    No wonder people turn their noses up at VB programmers with attitudes like that by the people that make the tools.

    Reply
  21. Robert McLaws

    Don’t just NOT call it refactoring just because VBers won’t know what it is. Call it "Refactoring", because that’s what it is, and instead teach them what it means if they don’t know.

    Reply
  22. Pingback: AddressOf.com

  23. Pingback: AddressOf.com

  24. Urs

    I’d like to have support for automatic elements reorder within a class. The purpose would be that it reorders all the elements of a class in a meaningful manner, e.g.

    Class Foo
    -event declarations
    -fields
    -constructors / destructors
    -public properites
    -public methods
    -protected methods
    -base class overrides
    -event handlers
    -private methods
    -interface implementations
    -inner classes
    End Class

    Elemnts of the same type should be ordered in alphabetical order.

    It often happens that the class gets cluttered with all sorts of elements during development and maintenance, making it more and more difficult to keep the elements in order. Also, if e.g. an event handler method is added to a class by a designer, it always gets added to the end of a class, instead of putting it in a more appropriate place.

    Of course, the order of the element types should be customizable. Also, the reorderung tool should optionally use #region directives to distuingish between element types.

    Thanks for considering & best regards
    Urs

    Reply
  25. theCoach

    VBDev1: Hey, VBDev2, I just read a book by Martin Fowler called "Refactoring" – it is exactly like "Emprettify Code" in VB.NET – it is almost like he stole the idea.

    VBDev2: Why are you reading software books? You are just a VB Developer.

    Not calling it "Refactoring" is a pretty insulting idea.

    Reply
  26. Mel Grubb

    Keep to industry standard names in this case. VB programmers get no respect because of questions like this. No wonder they/we’re seen as somehow inferior to C#. It’s simple not valid, but that’s beside the point. If, like so many other things in VB, you can pick a more natural, accessable, and sensible word, then go ahead. If there is no demonstrable advantage to the words and terms you pick, then don’t bother. It will only confuse people further if we have more terms for the same things.

    Reply
  27. Derek Hatchard

    When I used to train brand new programmers, they had to learn words like parameter and variable. Every programmer has had to learn domain specific terms. It is reasonable for a new IDE feature to carry with it a new term. If other tools call it refactoring, then VB.NET should probably call it refactoring as well.

    If there is a really compelling alternative to "refactor" I would be in favor of it. But unless it is completely crystal clear, there is no point in straying from what is fast becoming a standard term in the industry.

    My top picks (0 To 3) for refactoring support would be:
    0. Symbol rename
    1. Extract code block to method
    2. Promote local variable to class level field or Property
    3. Encapsulate class level field in a Property

    Reply
  28. Pingback: AddressOf.com

  29. Pingback: Julia Lerman Blog

  30. DaveG

    Just a few comments…
    – please make a simple dialog out of add parameter/remove parameter/rearrange parameters, not three options (though the underlying primitives might be useful for macros and such)

    – I agree 1000% about IDEA… and if you’re not modeling after IDEA (no need to do everything yourselves you know) please leave the door open for them to make these kind of extensions, plus various others which demand dynamic GUI integration in the editor pane and awareness of dynamic compilation results (which must be extremely resilient to syntax errors)

    – as much as refactoring, I need helpers to navigate to overridden parent methods and derived overrides, and helpers to tell me WHICH interface/override methods are NOT implemented yet and stub them out for me… another big time saver from IDEA (again, please do or leave the door open!)

    Reply
  31. Urs

    to DaveG: If you want to know which interface/mustoverride are not implemented, simpley go to the "Inherits foo" / " Implements foo" line and hit Return. VS will insert stubs for all the missing methods at the end of your source code. This works in VS.NET 2003.

    Reply
  32. Pingback: Bill Evjen's Blog

  33. Mike Blumenthal

    I just came across another almost-refactor (it’s not very structural so it might not be a full red-blooded refactor) – in this case I was using a Stringbuilder and as I added .Append statements I decided it would be nice to use a With block. So, select a bunch of lines and ‘convert to With block’ would be a nice feature. As I say, it’s less structural and more for readability, but, again, it’s something I would use a lot.

    Reply
  34. sg

    I IS VB GUY AND I KONFUZED. WHAT ‘REFACTOR’? I MUST GO LIE DOWN NOW. MY HEAD IS GOT ACHEY. I MUST HAVE BRAIN TUMOUR FROM TWO MUCH BIG WORD THINKING. WHAT IS A ‘FIELD’?

    Reply
  35. sg

    If us vb people are so dumb, why don’t they include a little animated geek to help us – the equivalent of the office assistant.
    "Hmmm. It looks like you’re trying to ‘Re-Thinkify'(TM) your code. Would you like some help?"
    "Hmmm. It looks like you’re trying to build an ERP solution. Would you like some help?"

    Reply
  36. Shane Courtrille

    Just wanted to give my vote for the ‘VB Programmer != Dummy’ faction. Why rename something like Refactoring when it’s already got a name? Wouldn’t it also hurt communication between pure C# and pure VB.Net developers when one is saying Refactoring and the other is saying ‘MakeItPurdy’ but they both mean the same thing?

    Reply
  37. Chris Bower

    I use VB over C# because of the IDE, even though C# is a more advanced language and I’m just as comfortable in either. I’m of the opinion that not calling Refactoring what it is just to ‘dumbify’ it down to the level of VB developers is insulting. Not all of us who choose to use VB are idiots….

    Reply
  38. Cathal Ryan

    The name isn’t hugely important, but unless there’s an obviously clearer name/term/syntax that you can use in VB.NET (as with New rather than class name for constructors or, arguably, Shared rather than Static for non-instance members), you might as well call it refactoring since it is a (fairly) standard term.

    If accessibility to less experienced programmers is a concern, maybe you could have a full refactoring feature set on an ‘advanced’ menu, and more understandable aliases for common features on the ‘basic’ or context menu.

    From my own experience, the most useful features would be:
    1) extract method – I find a need for his all the time in code I review
    2) promote local to parameter
    3) extract interface
    4) symbolic rename – very useful, but quite easy to automate anyway
    5) encapsulate field – obviously useful, but I rarely encounter a need for it
    6) add, remove, reorder parameter – all useful if not critical

    I guess its more migration than refactoring, but as Diego mentioned above; a way to automatically convert On Error Goto … to Try … Catch would be a real timesaver (though I suppose it would be difficult to do reliably), as would Wrap ‘this’ in a Try . . . Catch block.

    Reply
  39. Pingback: TOTO.net

  40. Steve

    VB is a serious language. Perhaps MS doesn’t agree?
    I work at a large company that develops large systems for hundreds of client companies. We (and our clients) consider ourselves to be professionals and we are now having to turn clients away because our hundreds of developers are fully booked.

    Until .Net we used VB for 99% of our systems. Now we use both C# and VB.Net, depending on circumstances. I have personally developed new systems in both languages within one year.

    I for one want both C# and VB to have similar features and THE SAME IDE TERMS so that we can more easily switch between them.
    I don’t care whether it’s called Refactor or something else, but please call it the same in both environments.
    New developers will have to learn what it is regardless of what it’s called.

    In order, these are the features I’d use most often:
    Extract method
    Add parameter
    Symbolic rename
    Extract interface
    Reorder parameters
    Remove parameter
    Promote local to parameter
    Encapsulate field

    And I like to write systems in debug mode and debug as I write. In VB6 there are days when I live in debug mode. When I can do that in .Net I’ll be a happy guy.

    Reply
  41. Warren

    What about refactoring with C++ ? Will that be included too ? If not I’d love to see that added.

    Please keep in mind that there is a LOT of C++ code out there, both old AND new,
    and that C# / VB are not possible choices for a lot of people out here.

    Warren

    Reply
  42. Joyce

    I agree that the term "refactoring" should be used in both VB.net and C#. In the spirit of standardization, these terms should be applied equally in all .net languages. Also, the term is widely used in extreme programming fundamentals which is not language specific and is becoming more widely adopted by the developer community. I think it like all other new features should be and usually are pointed out in early release documentation. If a VB developer is not familiar with the term, there is plenty of documentation to provide information on the topic.

    Just because we prefer VB does not mean that we aren’t skilled or familiar with other languages and concepts. I thought .net was about promoting standardization among languages by providing this common framework and making language choices more out of preference than out of necessity due to features or lack thereof. Then again, maybe that was the early days…

    Reply
  43. Eric Mutta

    I personally dont care what they call it – as long as its there. I wont feel ‘dumbed down’ either if they chose (IMO) somewhat simpler self-explanatory terms:

    *Improve code
    *Restructure code
    *Modify code

    or similar terms. I think what Paul Vick was implying is that people are more likely to click on a menu item with names similar to above, because they immediately reflect what you can achieve, without requiring you to look up anything. That will be true both for people who already know what ‘refactor’ means and for those who haven’t encountered the term before. Its similar to using the term "generics" or "templates" instead of "parametric polymorphism". They all mean the same thing, but you don’t have to know about type theory to guess what "generics" would be about. Another example is SQL..how many people would be using it if it was called tuple-relational calculus?

    And as those who like to fiddle with their IDE’s would know, regardless of what MS choose to call it, you can *change* the text displayed in the menu to whatever you want. Heck, you can even change the mnemonic, the shortcut key, the image next to the menu item, move the menu onto a toolbar, move the item onto another menu…the possibilities are many.

    Reply
  44. Pingback: Stefan Demetz

  45. Jeff Morey

    Please call it Refactor just like the industry term!

    Just to add my .02 to what most of the people here are saying.
    I am a vb6 MCSD and I have passed two vb.net certs (winforms, webforms).
    I know what refactoring is and vb/vba/vb.net has been my world since 1999.

    I am excited to get refactoring as it is a large reason why some developers in a study group I was involved in switched to java. Their explanation was the free XP tools were better in that world. They felt XP was the way to go and it integrated better with the J2EE camp.

    I believe in DotNet. Please give both vb.net and C# Refactoring and please call it what it is.
    And like every other DotNet developer I know, please give us debug/edit/continue again. After Intellisense that was the most important tool a developer needs for RAD.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *