Sunday 24 January 2010

Relationships, testing and non project problems

Relationships

So far this week I've looked into issues with relationships between races and swimmers. In order to represent this correctly I've created a raceRecord which belongs to race and also to a swimmer. I struggled with how to do this but I found the answer in Grails In Action (page 87 in case you're curious). Simply:

static belongsTo = [Race, Swimmer]

When the controllers and views are generated all seems to be as it needs to be.

Testing

Ok so I want to believe in the whole Test Driven Development (TDD) ideal but Grails just seems to be so easy to whip stuff up and tests are just not sexy to write. However I've promised myself that I'm going to do things right. I spent some time writing a couple of basic tests for the constraints on the domain classes. It was here that I added a grails plug in (the code coverage plugin). This allows me to run test-app -coverage to see stats on the amount of test coverage I have which I find pretty motivating. Now time for a little rant...

I know that test coverage in and of itself is not a concrete guarantee of code perfection but its got to be better than not testing at all. Yes the quality of the tests is fundamentally important but its not enough to say that just because tests can be poorly written so why even bother having them. Surely this goes to your own integrity to make sure your code (and your tests) does what its supposed to do. If it sounds like I'm excited, let's just say that this has been a bone of contention in my day job recently. Anyway the swim project will not progress any further until all domain classes have tests for constraints to start with. I've updated to the new Grails Textmate bundle too so this should make my test writing quicker.

OS and other disasters

I'd previously partitioned my MacBook hard drive to allow me to install Windows 7. After a couple of days I ditched it for Ubuntu and had been happy with that but with no time for OS experimentation decided to reclaim the partition for OS X. However I couldn't simply re attach the rogue partition and had to wipe and reinstall everything. I do have an external hard drive but its partition as FAT32 and therefore cannot be used by OS X's Time Machine. Therefore I had to manually copy my files over and then copy them back. This was a significant time cost and I think with such cheap hard drives I think I'll get another for Time Machine to avoid this drama next time. The whole process was made easy with MacPorts though.

In better news, I've started following this great blog from a mate of mine about his quest to build a python driven robot. Its well worth the read.

No comments: