Stop writing code you don't need!

The situation

You’re writing unit tests for your new web app to let people create their own custom oatmeal-flavored razor blades when you have an epiphany. Ther razor blades are worthless without an accompanying yak scented razor!

So you start writing some unit tests for your innovative razor.

Then another idea drops on your brain like a Pan-Galactic Gargle Blaster. The razor should also be usable as a rake because, remember, Fall is here and there are leaves on the ground!

So then you start writing your tests like a good little TDD’er to add a rake to your yak-scented razor that uses oatmeal-flavored blades.

And then, ooh, what if we store the state of the face being shaved and yard being raked in a bag of holding. Everyone says that the bag of holding is web scale!

STOP!

The problem

In a nutshell, bottom-up thinking leads to featureitis (yes, an inflamation of features). When you see your problem domain through the lens of unit tests, your inclined to consider features that you may not need.

The solution

You need to drive your development from the user’s level down through to the model level.

You need to change your perspective.

You need to do Test Driven Development (a.k.a Behaviour Driven Development) – but using acceptance/integration tests first and supporting them with unit tests as necessary. Start by writing an acceptance/integration test that describe a feature that your user needs. Then you make the test pass (hellooooooooo red-green-refactor). Rinse and repeat until you’ve written tests that describe each feature needed by your user(s).

Congratulations! Your app is (mostly*) complete!

More to the point: you probably wrote only the code that you need to satisfy the needs of your user(s). This will save you time and you, or your customers, money.

*: Complete is relative. You rarely know that your application handles every possible condition

Posted by evan on Thursday, December 02, 2010

blog comments powered by Disqus