[ Bjarni R. Einarsson / blog: IS EN ]


Test-cases and Perl

2000-11-24 12:54
Today I released a new revision of my email sanitizer to the world. This latest release features a set of automatic tests, to verify that the program keeps doing all the important stuff right even after I've modified it.

I should have done this long ago, and would like to encourage all Perl programmers to do something like this themselves. The is especially important for Perl code, because although Perl is in many ways an excellent language it is not strongly typed and it allows code to be generated at runtime. This means that the compiler (or interpretor, in this case) can only check some very basic things when you compile the program - many errors cannot be caught until the program actually executes the broken code. If the broken code is rarely used, then you can expect unexpected crashes... so ideally, when you write a Perl program you should also implement and maintain a set of tests that force every single line of code to execute at least once.

The fact that this is necessary at all is one of many good reasons some people think Perl is a Bad Language.

The critics do have a point - but I like Perl anyway. It's a powerful, comfy language. The very features that make it more error prone facilitate very elegant implementations sometimes. You just have to be careful - and even if Perl didn't have these flaws, then you would want test-cases, since they provide assurance that ongoing development doesn't accidentally alter the behavior of the program.

   
Name:
Subject:

Note: If all you want to do is correct grammar or spelling, please send me e-mail instead of cluttering up the diary. Thank you!

Yes! I will write my own HTML!    

Valid HTML: <P>, <BR>, <A HREF="...">...</A>, <UL>, <OL>, <LI>, <I>, <B>
Blockquote and image tags don't work!

Please leave these blank:

Nýtt í dagbókinni