Coding by need

Test driven development essentially means that the only legitimate reason to write code is a failing test.

I think this same "laziness" principle applies on the coding level, too: Failing compilation should be the only legitimate reason to create/modify classes and methods.

In practice this means that in general you should first write the call and only then the called class or method. I call this quickfix coding (from the quickfix feature of Eclipse).

This relates closely to the coding by intention principle mentioned in some XP book (maybe XP installed). Coding by intention helps in keeping your thoughts in one thing at a time. Furthermore it produces more readable code.

Quickfix coding is more economic, too: you need fewer keystrokes as the IDE creates the signature for you. And you'll rarely need to manually open files or keep several of them open: if you start from the caller, you can always ctrl-click the call to open the called file and close it after the modification.

I think Coding by need is a nice common name for TDD and Quickfix coding.

Originally published on 2005-10-07 at http://www.jroller.com/wipu/entry/coding_by_need under category Java