in reply to How to write programs?

  1. Document the behavior the program is meant to exhibit.
  2. Write tests that would work if the program behaved as documented.
  3. Write code that will pass the tests.
:-)

update: and sprinkle with liberal amounts of review by peers and refactoring at each step; if the documentation can't be understood, the interface is too complicated, so aim for clear documentation first.