Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Testing: Fun for the family

by hardburn (Abbot)
on Mar 09, 2004 at 14:17 UTC ( #335098=note: print w/ replies, xml ) Need Help??

in reply to Testing: Fun for the family

I've been trying to discipline myself of late to always write my tests first. In a personal project, I found two things: first, I can see the code working right away, and second, I tend to write code in such a way that it's easy to write tests for.

The first is important on code I'm not being paid to write, because I have a tendancy to write all the interesting portions of the code and then stop. I can't tell you how much 3-5 year old code I have in my projects directory that won't even compile because I gave up on it.

The second is really interesting. I often find that the code that is easy to test also happens to compartmentalize into subroutines well, so it ends up encouraging good design anyway. Certainly a case of constructive laziness.

Have other monks that use Test Driven Development found the above to be true?

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Comment on Re: Testing: Fun for the family
Download Code
Replies are listed 'Best First'.
Re: Re: Testing: Fun for the family
by swngnmonk (Pilgrim) on Mar 09, 2004 at 17:38 UTC

    I've found this to absolutely be the case. I only started writing tests for code I was working on about 9 months ago, and I'm a believer. For code I've written tests for, I no longer dread re-opening it 3 months later. Happened this morning, in fact - I had to fix ambiguous behavior in a core module, and I knew the tests (not only of that module, but the entire system) would help protect me from doing something seriously bad.

    Testing has worked wonders for me when it comes to API developement - especially when I know other people are going to have to work with the API I'm developing. Writing tests forces you to run your proposed API through its paces before anyone else takes a look at it. Maybe it's not tuned to race yet, but at least you'll know all the wheels are bolted on and the engine runs. :)

    Check out Test Driven Development (amazon link) by Kent Beck. All the examples are in Java, but it's a good (fast) read on how to approach coding in this fashion - through heavy testing, coding, refactoring, and testing again.

    As others have said, testing isn't a magic bullet. I view it kind of like safety rigging in construction work - you could get by without it, but would you really want to?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335098]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-11-29 13:43 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls