Compartilhar via


Are Refactorings safe?

The C# refactorings we're building in Whidbey are designed to be reliable. 

Not all of our customers use TDD, but many will use the refactoring tools we build.  If the tools don't work reliably, users will stop using them.

The big exception was unbuildable code.  We can't really guarantee preserved semantics of illegal code, since the semantics are undefined!

If you're doing TDD, this exception matters less, as you keep your code buildable pretty much all the time.  It's a prerequisite to running the tests, right?

There are some other subtle exceptions:

  1. Reordering the parameters to a method can have an unforeseen effect if the parameters you pass have side effects.  The side effects now happen in a different order.
  2. Removing a parameter to a method will change behavior if you pass a parameter with a side effect.

Both of these are difficult to guard against.  What should we do?  Remove the refactorings because they're unsafe?  Add cumbersome warning messages on the UI?

However, we're definitely working hard to make Rename and ExtractMethod very reliable.  They're the most important Refactorings we can provide, and we want you to use them a lot.

Comments

  • Anonymous
    February 26, 2004
    I would prefer warning messages to removing the functionality, especially with a "do not show this message again" option. :) Why limit advanced users in catering to the less-advanced users?
  • Anonymous
    February 26, 2004
    I agree 100% with Darrell
  • Anonymous
    February 26, 2004
    The comment has been removed
  • Anonymous
    February 26, 2004
    You mean when you edit in the area that says "Do not edit"? wink
  • Anonymous
    February 26, 2004
    The comment has been removed
  • Anonymous
    February 26, 2004
    The comment has been removed
  • Anonymous
    February 26, 2004
    The comment has been removed
  • Anonymous
    February 26, 2004
    +1 for Darrell
  • Anonymous
    February 26, 2004
    I'm perhaps missing something but what's TDD?

    I agree with Darrell btw.
  • Anonymous
    February 26, 2004
    TDD == Test Driven Development. If that was a serious question, it warms my heart that you can still create excellent software (LLBLGenPro) without necessarily requiring TDD (Of course you might have done it that way, just under a diff name)
  • Anonymous
    February 26, 2004
    Jay- Which "Do not edit" area are you talking about? I have seen nothing like that...
  • Anonymous
    February 26, 2004
    Wow, I'm glad you posted your link Frans, if I ever clear all the red flags off my desk I'm going to have to take a look at the LLBLGenPro demo :)

    My feeling on refactorings is... I hate getting warnings and notifactions popping up at me, because 90% of the time, I already know that what I did was potentially dumb, and I want to do it anyway, and the 10% that I SHOULD read the warning, I never do because I'm trained to just click ok/cancel/ignore/whatever.

    I think that leaving comments around can be one way to do it, especially on unbuilt/dirty (as in edited) code. I also think that the new "color coding" features going in to whidbey could be used... maybe have a special color for code that's been changed by the refactoring tool since the last build or something?
  • Anonymous
    February 26, 2004
    Jay,

    One option to consider with the refactoring is a preview mode, where the user can inspect the (possibly dangerous) refactoring and decide for themselves.