[ Content | View menu ]

Tetris or Simulated Annealing

Written on 2 Apr 2005

I was working with a colleague on cleaning up an ugly corner of our codebase. We weren’t quite sure of the best solution, so we were doing some exploratory refactoring. The session was getting a little tense until we discovered that we had different approaches to this activity. Once we’d clarified this, we picked one and things went smoothly.

My colleague preferred to flatten the code out, putting back some duplication we’d removed earlier, and then look for alternative refactorings that lead in a better direction. This might be described as simulated annealing, moving away from a local minumum to find a better one.

My habit is to chip away at the code by finding little duplications until larger patterns become visible; think of the lines disappearing in Tetris. As a technique, it probably requires more of an act of faith that things will work out in the end.

Conclusions (i) There’s always another approach that you haven’t used yet. (ii) It can take a while to calibrate with your colleagues.

Filed in: Agile Programming.

One Comment

Comments closed

  1. Comment by Robin Curry:

    “think of the lines disappearing in Tetris” - I made a similar observation several weeks ago on my blog that software development was like Tetris (http://www.robincurry.org/blog/SoftwareDevelopmentTetris.aspx ). Great minds think alike I guess. But you were probably already thinking that, huh?

    3 Apr 2005 @ 01:43