Thursday, September 27, 2018

How Much Time Do You Spend Refactoring?

Software development is really mostly about design, so we should spend most of our time refactoring.

Personally, I spend almost all of my time refactoring. If a feature doesn't "fit" in my current design, it's going to be hard to test, so the test-effort tells me it won't fit.

When that happens, I stop. I usually delete the test outright. If I know it's going to be a really fast refactor, I'll comment it out for a few minutes.

Then I refactor. I refactor, refactor, and refactor some more.

Eventually, I will have addressed the problem - usually by creating the right abstractions or encapsulating something.

At that time, I can safely and easily introduce my new test and my new behavior. It's an expression of my philosophy that we should make work easier rather than work harder.

When I do this, the typical effort for a new behavior trends down in an asymptotic way.

Two charts. The left is captioned "time spent mostly refactoring" and shows a curve approaching an horizontal asymptote. The right is captioned "time spent mosty adding functionality". It shows a diagonal line. In both charts, the horizontal axis represents the time or age of a product and the vertical represents the effort required to add a given unit of functionality.
The effort per unit of functionality as a product ages under two alternative strategies