29 March 2005

Extreme refactoring?

Brian Button has written a demo of extreme refactoring using the following rules:

  1. Methods should be 1 line long. Anything longer than that needs to be looked at closely.
  2. Aggressively eliminate all duplication, specifically duplication involved with iterating over containers several different times in similar ways
  3. Use no private methods.

The first rule seems fundamentally flawed to me. At the point where you sacrifice clarity for brevity, you end up with software that doesn't do its job properly. That is, the software no longer clearly indicates its intent, and becomes makes life harder for the people who are maintaining it.

I noticed however that Brian's code isn't at all difficult to read. But remember that the task he's working with is a very simple problem. I believe (and have seen from experience) trying to get complex algorithms down to one-line methods can often obscure the intent of the code.

That's not to say simplicity isn't the goal. But shortest isn't always the simplest.