Leonardo da Vinci, when he painted Il Cenacolo, or as we call it here in the US, The Last Supper, produced studies for the work before he began to paint. Later, when the painting was restored in the 1970s, researchers used infrared reflectoscopy to look underneath the outer coats of paint to find that the original work of art was in fact very different from what tourists had seen for the past few generations - mostly because of the poor showing conditions for the painting, but partly because Leonardo da Vinci painted in layers, and modified the painting in its creation.
The 'First Sketch' of Il Cenacolo
Programming is not very different. Many modern practitioners (and I count myself among them) believe that good production code is never created on the first try. To facilitate this process, we write 'spikes' or trial applications to quickly flush out a good design that we can use for the final version.
Another modern software development methodology is
TDD (Test Driven Development). TDD adherents believe that no code should be written without first writing a test that describes a software requirement, and only the minimum code needed to satisfy the test is written to make the test pass.
The reasons provided for writing code this way are manifold:
- The lines of code needed for the application are minimized.
- By virtue of the process used for development, the code will have very few bugs as long as the correct requirements are used for the tests and the tests are written well.
So here is my conundrum: Should we use TDD when we write spikes?
After all, I am throwing out the spike when I am done! So...
- I am not concerned with minimizing lines of code, as I am not maintaining the code for a spike.
- Also, I am not concerned if there are bugs in the spike. It's never going into production.
In fact - and here's a major point - when I use TDD when I write spikes, invest so much time into writing the tests, and mocking or injecting dependencies, etc... well it's easy to fall in love with your little TDD spike and keep it instead of buckling down to redesign the component into a thing of beauty.
On the other side, I know that TDD is a wonderful habit - and I should be writing using TDD as much as possible. Perhaps the extra TDD writing experience will do this coder some good.
What do you think?
Happy coding!
Jonathan Starr
improve my => 'code'