I've never written anything before that was meant to be large. Recently, though, I've started a hobby Perl project that is fairly large in scope, so I've been thinking about design.

My usual design process goes like this:

  1. Fix a small problem with a small Perl script.
  2. Somebody wants more functionality, kludge it in.
  3. Is the code utterly terrible now? Maybe refactor something.
  4. Goto 2.

Code gets really terrible, really quick this way. I know you all probably know that, but it has surprised me very quickly how crappy things can get if you aren't planning ahead. The only reason it stays sane at all is the set of automated testing tools on CPAN, which have saved me probably thousands of hours of bug hunting. (The "looking for what my last change broke" kind of hunting).

Back to now: I was trying to spec out what I wanted to do, and I had a thought: What if I wrote the tests first? Possible pros:

Does anybody else start with the tests and go from there? Heck, for all I know, this is what everybody does already, and I'm just behind the times. If people do go the "tests first" route, are there any pitfalls? I can't think of any cons to going this way, and that sort of worries me.

In reply to Does anybody write tests first? by amarquis

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":