Inside SWT

Friday, March 02, 2007

Refuctoring your code

Have you ever done this: Tried to refactor your code ... and failed.

Amongst the many masterpieces that sit at the bottom of the Eclipse stack, SWT is one of the gnarliest. Implemented in Java, it's coded to the metal. Many things are inlined. It's full of version checks, work arounds for operating system bugs and wild hacks that make everything go. It's backwards compatible to the day it first shipped, yet somehow embraces and exploits the latest operating systems features.

Don't be afraid. This is normal for a high performance, operating system level library that isn't waiting for the hardware to get faster.

Anyway, while attempting to refactor some of the more crufty code, I failed. The refactored code just wasn't any better so I ran away from the changes. It took strength to step back, evaluate the situation, weigh the pros and cons and decide to throw it away. Really, you are throwing out more than code. It's the investment in the new way of thinking, rather than the changes, that you have trouble parting with.

Code that is refactored into worse code: that's refuctoring!



  • Haha; thanks for belly laugh. I think you've coined a classic term for an all-too-common situation. Cheers.

    By Blogger Benjamin, at 9:48 PM  

  • I've mal-refactored many times myself, but it's not always a waste. Often you'll realize, 1/2 way in or more, that the current approach will never work, or there is a better one. Even with that first refactoring, that doesn't survive, you've done some Knowledge Acquisition.

    Even if you can't refactor, that the current whack of code can never really get better, you've still learned something. Just make sure you keep notes, because otherwise you might be tempted to try it again, in a couple of years.

    By Blogger Patrick Mueller, at 12:11 AM  

  • What you are saying is, "smart people learn from failure". I agree with that statement.


    By Blogger Steve, at 2:25 PM  

  • This term's been around for a while:

    Check out the presentation!

    By Anonymous Joe Beck, at 6:17 AM  

  • Hilarious! I am a man beside my time.


    By Blogger Steve, at 8:45 AM  

  • It's backwards compatible to the day it first shipped, yet somehow embraces and exploits the latest operating systems features.
    Backwards compatibility is a sin. It led windows to where it is now - the nightmare-OS. Plus, swt doesn't really use latest OS features ;)

    By Anonymous Anonymous, at 5:23 AM  

  • Anon-y-mouse,

    Either you believe that you should not break people and cause them to rewrite every release, or you don't.

    Which features would you like to see?


    By Blogger Steve, at 9:54 AM  

  • Steve,
    It's true, that you're either believe it, or not, but saying about breaking people and causing them to rewrite every release is definitely wrong.
    Lots of your posts show that you admire the backwards compatibility that was achieved on windows systems prior to vista, but look, you cannot support 10 years old API. Plus, you have to have enough courage to admit, that API you created first was bad, to deprecate old methods in next release and delete them in the one after next. With your strategy, the number of people, that rely on deprecated methods, grows and grows, holding and sinking you, and you just don't have time to look to the future because all your time you look in the past. And really, M$ is not a good example to follow.

    By Anonymous Anonymous, at 4:23 PM  

  • I understand your argument and disagree with the blanket conclusion. It all depends on the API in question and how hard maintaining it is.

    As for Windows being a mess, they are all a mess (really, I know).

    Finally, consider this: You are a business built on Windows with a large installed base. Microsoft tells you that all the software you have today is broken and you must rewrite.


    By Anonymous Anonymous, at 9:24 AM  

  • It's would me much more realistic example, if MS contact me and say "hey, we gonna have API changes in our next release, here is new SDK, so be ready" Of course, silently changing all the API is no good at all, but sticking to it forever is not good either.
    Anyway, we can argue forever and I guess we both have more interesting things to do :)

    Thanks for a good talk,
    PS Yep, I'm now a guy with account :)

    By Blogger dante, at 6:23 PM  

  • Yup. I understand and respect your point of view.


    By Blogger Steve, at 9:54 AM  

Post a Comment

<< Home