Why I’m Considering a Code Refactoring Tool

May 13, 2011

Nerd

I’ve never had an interest in a refactoring tool until now, primarily because I don’t want to fumble around, not knowing where to find things or attempting the wrong shortcuts when I’m at someone’s computer who doesn’t have (Resharper, CodeRush, JustCode, etc).

I purposely never adopted anything like a Natural Keyboard for the same reason. I’m a fan of defaults.

The other reason I’ didn’t have an interest prior was because everything I’ve heard from the users of the various Refactoring tools (it can do blah!), I’ve been able to reply with, “that’s built into Visual Studio.”

Keep in mind that I’m specifically referring to technical things like refactor/rename (not code analysis features).

I am currently building a library to interface with a 3rd party REST service. Using “Paste XML as Types” creates properties with the same names as the REST response (like credit_card, first_name, etc), and names backing variables classname + “Field” (like credit_cardField, first_nameField).

I have started manually changing them to our work specs (FirstName prop with _firstName backing var, decorated with [XmlAttribute(AttributeName = “first_name”)] for the Serialization/Deserialization, for example),  but it’s REALLY tedious.

This is why I’m considering a Refactoring tool.

Summary:

I need this:

private string first_nameField;

public string first_name
{
    get
    {
        return this.first_nameField;
    }
    set
    {
        this.first_nameField = value;
    }
}

Refactored to this:

private string _firstName;

/// <summary>
/// Purchaser’s first name
/// </summary>
/// <example>
/// Ford
/// </example>
[XmlAttribute(AttributeName = “first_name”)]
[Required]
[StringLength(15)]
public string first_name
{
    get
    {
        return this._firstName;
    }
    set
    {
        this._firstName = value;
    }
}

Or this (with the option to make them automatic or not, as I do need backing vars in some cases):

/// <summary>
/// Purchaser’s first name
/// </summary>
/// <example>
/// Ford
/// </example>
[XmlAttribute(AttributeName = “first_name”)]
[Required]
[StringLength(15)]
public string FirstName { get; set; }

(Obviously I’d have to go back in with the Data Validation Attributes, but I left them in to give a complete picture)

If you know if any tool that will support that, please let me know in the comments!

5 Comments on “Why I’m Considering a Code Refactoring Tool”

  1. Rory Becker Says:

    This post on CodeRush resources is also worth a read through … CodeRush Resources

    Reply

  2. Gabry Martinez Says:

    Cori I’m not a big fan of this kind of tools either, but one that I have used it’s Resharper. I don’t know if the license could be a stopper for you, but why don’t you give it a try. Also there’s a lot of users of it out there that I’m sure can help you with any question you have. :).. Good luck with your search!

    Reply

  3. Rory Becker Says:

    Reposting previous comment with corected links

    The CodeRush features that will make most sense for you are Templates, Refactorings, Extensibility and Support

    Our Templates can create properties as you indicate from the get go with only a few keystrokes…. see CodeRush Templates 101 and are fully customizable

    Our Refactorings can remove backing store and convert to auto-implemented properties in a couple of clicks / keystrokes and over 180 other useful operations.

    Our Extensibility ensures that even if we don’t support the exact refactoring you need out of the box, it can still be built as a Community Plugin

    Our Support is second to none. We’ve been known to turn around new open source functionality in < 24hours.. We've even implemented functionality live in webinars in < 15 minutes.

    Feel free to contact me on twitter @Rorybecker or via email Roryb@devexpress.com for any further details…

    We may even schedule a dedicated training webinar to help you get up to speed. :)

    Reply

  4. Mike Strobel Says:

    Sounds like what you need is ReSharper’s Structural Search and Replace feature. Basically, you can search for code conforming to a certain shape/structure and do simple to moderately complex transformations.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: