2004-05-28

Test Driven or Test First coding

I don't think that I've ever made a distinction between Test Driven coding and Test First coding, as PragDave does. Dave's description of the two makes sense to me, but perhaps not all the way.

In test-first, you never write a line of production code until you first have a failing test that will be "fixed" by the code you write. Want to write a new class? First write a test that instantiates it, watch the test fail, and then implement the class body to fix the broken test.

This could be interpreted in two ways. The tough interpretation says that if you want to create a class named Firecracker you first add a test (not necessarily a test case) that tests instantiation of the test class. In java that could be something like this.

public void testFirecracker() {
 assertNotNull(new Firecracker());
}

This seems too rigorous to me. I did this back when I first started playing with UnitTests. I even went further and created unique test case classes for each class added, but nowadays my interpretation is looser; it takes so much time and effort to create and, most of all, maintain all these tests.

The maintainance required is actually what bothers me the most. I feel that you're much more locked into a particular design when working this way. Instead I interpret the Unit in Unit Testing as something above the class. The tests in my test cases today tries to express the inteded usage and functionallity of a specific class or a set of classes. I add a lot of code around the class being tested—other classes, C-functions, whatever needed to make the tests run—and my reasoning is that my tests will eventually be expressive enough to catch (almost) all possible errors. And, I'm always writing the tests first so I do consider myself a test first coder, from time to time.

I don't think this interpretation of mine is in conflict with PragDave's definition of test first programming. I do write a test that tests instantiation of a specific class, but indirectly. In my opinion, the instantiation test doesn't even have to utilize the class in question to fullfill the test first requirement; the effects of the indirectly used class are covered in the test. I'm not sure if this is what he meant though.

2004-05-27

Floating-point arithmetic

I can't call myself a computer scientist but one day, one day, I'll read up on what every computer scientist should know about floating-point arithmetic and I will have taken a step in the right direction.

2004-05-04

UFS, HFS+ and international characters

Today I stumbled across an issue with filename encodings on Mac OS X. We have a server that has been around since the good 'ol days of rhapsody, and since many files on this server differ only in the case of their names we've stayed on UFS. With the introduction of Case Sensitive HFS+ in Mac OS X version 10.3 I thought the time was right to migrate the old UFS filesystem.

There's a problem though. It seems UFS is quite forgiving in respect to the encoding used in filenames. A lot of files on our UFS disk has been FTP:ed from Windows machines and have swedish characters in them, encoded in Windows Latin. These files cannot be copied to an HFS+ partition as HFS+ seems to require correct UTF-8 encoding (or, as discussed on this page, HFS+ actually uses an Apple-modified version of Unicode's Normalisation Form D).

I'm not sure how to handle this. We could convert all filenames on the UFS disk to UTF-8 (which HFS+ seems to handle) before moving them to an HFS+ partition. I don't think this solves the problem where someone uploads a file with international characters in its name from a Windows machine using FTP, or when a cgi script like UseModWiki tries to create a page with international characters in its name. Perhaps there are nice workarounds to these problems, but for now I feel it's safer to stay with UFS.


Hosted by Oops FREE THE MOUSE
This site is powered by Burger; powered by djbdns; powered by lighttpd; powered by FreeBSD; powered by electricity.