Tuesday, June 23, 2009

Code refactoring

is like trying to deconstruct a sweater into independent and usable separate colored balls of yarn.

Images from here and here.

4 comments:

  1. It is a good analogy but not entirely true. It is more like forming a clay ball into well defined (lego?)parts but the difference between your analogy is that the parts as still connected but can be separated at any time.

    ReplyDelete
  2. I guess it depends. When I was making this analogy, I had Javascript in mind. Most js hacks involve a huge set of function definitions and calls, all intertwined and confusing to figure out. Code refactoring for such hacks involves making logical separations in the code and define proper abstractions.

    ReplyDelete
  3. I just wanted to point out that although you extract the code logically, it is only from the developer's point of view that the code has been separated. For me when you refactor, you are positioning the code in such a way so that it will be re-usable when you need it to be. It has not been (really) separated yet. Until the parts have been used in multiple completely different projects by different people, then you can safely say that the code has been separated into multiple threads/yarns. :) Very colorful sweater by the way

    ReplyDelete
  4. Its not a perfect analogy definitely, but its nonetheless entertaining (especially with the colorful sweater as you said) :P

    ReplyDelete