Tuesday, January 31, 2006

The most satisfying thing to do with source code

Delete it.
And I don't just mean deleting bad code, in the same sense as you might enjoy clearing junk from your yard. I think it's even more satisfying to delete code that you like, that you had a hand in creating, that you feel proud of.
Deleting good code makes sense either when circumstances have changed so that it is no longer required, or when the code has served as a stepping stone but will not be used in the final solution.

Pseudo-examples

Changing Business

  1. Write code to solve a business problem
  2. Deploy the code into production and use it to run the business
  3. Change the business, possibly due to a short term business opportunity
  4. Delete the redundant code

Exploratory Test

  1. Write a unit test to express how a part of the system should operate
  2. While trying to make the test pass, discover a different abstraction that will be easier to test and implement
  3. Write new tests and implementations using the new abstraction
  4. Delete the original unit test

Refactoring Pontoon

  1. Attempt a refactoring that is too large to complete in one step.
  2. Write pontoon code, possibly many new classes, that will keep the system in a working state while the refactoring is in progress.
  3. Complete the large refactoring after several steps
  4. Delete the pontoon code
Once good code has been deleted, it's like an exemplary citizen - not only did it serve its purpose well while useful, but it imposes no burden on the remaining system after it has gone. Less code can mean less complexity, and a lower cost of change for the code that remains.

Deleting "perfectly good" code might seem wasteful, but going down that road is going bring you to the old fallacies about predicting programmer productivity by measuring their typing speed.

I've started to realise I feel proud when I delete good code, with an environmentally friendly kind of smugness. Hopefully I'm doing my bit to reduce my complexity footprint on the software landscape.

0 Comments:

Post a Comment

<< Home