Refactoring vs performance optimization

The thought popped up into my mind a while ago, that there is actually a striking similarity between refactoring and performance optimization. Both of them…

  • are meant to make the program better.
  • preserve semantics of the program (hopefully).
  • should be driven by a real and provable need.
  • can be harmful when premature/speculative.

In fact, they have the same goal as well. They are both meant to to make the program easier to interpret. The only difference is that refactoring tries to make it easier for the developer, and performance optimization for the computer.

5 Responses

  1. Ah, but you forget that optimizing for performance is likely to reduce the readability of the code.

    This goes against the idea of refactoring. :)

    Foo Bar - January 7th, 2007 at 17:29
  2. Hi, dear mr Bar. ;-)

    Sure it does, but then again, the goal of performance optimization is to increase the “readability” of the code for the computer, not the human. :-)

    Henrik Jernevad - January 7th, 2007 at 17:56
  3. Ah (I’m back!).

    Well, while I guess you could read it that way; I never did. In fact I had to dig after the book “Refactoring” by Martin Fowler to see if I completely missed that subtle point. And to quote him on what Refactoring is:

    “Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable layout.”

    To me this sounds more human oriented than machine oriented. But hey, both works, I guess. :)

    Granted, his book is a bit soft-core and only introduced refactoring to the masses so it’s by far not the only definition. :)

    Foo Bar - March 6th, 2007 at 22:43
  4. Oh god, ignore my previous post. I completely misread what you said :)

    Foo Bar - March 6th, 2007 at 22:51
  5. …takes a few steps back and just nods. See you in a couple of months again! :)

    Foo Bar - March 6th, 2007 at 22:52