Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

  • Get thinking about potential problems/sticky spots/corner cases earlier.
  • Write code that uses the module before you write the module. I often write a module only to find out that it is awkward to actually use later.
  • Be thinking about the big picture, and how different components will work together in usage.
  • xdg mentions: If you've made a test bug where a test trivially succeeds without checking anything, you'll find it this way instantly.

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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-20 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found