I’m not a newbie since I’ve been programming on and off since 1983, but I only have real experience with scripting languages like Applescript, ARexx, HyperTalk and Bash.
I write scripts to automate data entry, batch process images and convert file formats. I dabble at Processing, Ruby and Python.
Most of the programs I write are under 200 lines with at most 10 functions. I wish to write larger, more capable programs in the future. I want to improve my practices to avoid creating fragile, unmaintainable messes. The programming environments that I work in (Script Editor.app and Text Wrangler.app) have no support for automated testing.
At the scale that I’m working now and writing procedural (not OO) code, is it appropriate to write unit tests, which I understand are:
short programs to test individual functions before combining them into a fully functioning larger program.
Are unit tests worthwhile compared to their cost when making programs at this scale?
Definitely beneficial as writing the tests may help verify the design of your functions (does the API make sense) and helps protected you from mistakes in the in the future. Unit tests can also act as a contract for your functions which can indicate how the functions should be used and what they expect.
With shorter programs that are clear simply by reading the code it may not be beneficial to thoroughly test it if you do not have alot of time. Otherwise I have to agree with my colleagues here that unit testing has a variety of benefits and is helpful for even for small projects.
Warning: The following links may not be applicable but the ensuing discussion is a good read.
There has been some discussion recently within the blogosphere as to when testing is appropriate, specifically Test Driven Development (TDD). You might want to check out some of the articles such as these three articles by Roy Osherove.