Yes. More on testing, and probably nothing new or revolutionary either. As I’m attempting to write tests, fix stuff, and sort out some fun multi-byte character issues, I’ve realized again at how much better it is to be on a project once you reach the state of being proactive, instead of being reactive.
The problem with reactive bug-fixes/features/HOLYCRAPTHISNEEDSTOBEFIXEDRIGHTNOW/etc. is that if your codebase has any sort of, say, complex business logic – it’s likely that reactively doing updates in this fashion is going to come and bite you in the back side.
Being able to proactively perform these updates is a state that I think applies if you have enough unit tests, functional tests, integration tests, and maybe even regression tests in order to ascertain that the new code that you’ve written doesn’t wreck anything currently deployed, and with any luck, you’ve also written some new tests that test the new code that you’re deploying. Go figure (I told you that I didn’t have anything new or revolutionary that I wanted to say).
I spent a bit of time trying to elaborate this relationship in a pretty picture – and here it is:

Basically, the less tests you have, the more reactive you are, and the more screwed you are. The more tests you have, the more proactive you are and the less screwed you are. This is what I shall now refer to as the Triangle of Happiness (the green one).
It’s also worth noting that the # of tests (this doesn’t necessarily mean # of tests, but could be code coverage, whatever) – is decidedly NOT a linear relationship with proactivity. Writing tests definitely reaches a law of diminishing returns. As your screwed-factor (reactivity) approaches zero, and your proactivity-factor approaches infinity – the number of tests that you have to write in order to further increase your proactivity-factor is exponential (give or take).
So, tests are crucially important so you don’t get screwed, but 100% code coverage is absolutely not cost-effective and (in my opinion) not necessary (unless maybe you’re NASA, or people die when your software sends an order of Cookies to Canada instead of California).
Right now, I’m finding it quite ironic that I’d been thinking about this all day yesterday, after trying to retroactively write some tests for a project that I came into rather late in the lifecycle.
Cedric just posted an entry with the exact same title, almost as if to taunt me with his infinite testing wisdom.
At about 200 times during the day yesterday, I came across a piece of code and thought to myself:
“How in the &$^%#@! am I going to write a test for this?!?”
So with any luck, Cedric will be able to get Hani to stop biling and whining about XML – and finish their testing book so I can go buy a copy.
In the meantime, it seems like the new question I am going to ask myself when designing a piece of code is something along the lines of:
“Sure, this design is elegant, but is it testable?”.
And as Cedric mentions, writing testable code is not necessarily writing code that is better designed.
It’s been a long time since the last time I installed and used Ubuntu, but with another shiny newish version out, 6.10 or whatever it is, I wanted to give it another go. Of course, I’m afraid of hard disk crashes (as should you be), so the first thing I do is set up a software RAID. I’ll go with a RAID-1 (Mirror) so we’re protected in the event that one of the disks decides to up and die.
The last time I did this was for Ubuntu 5.10 (don’t ask me what nifty nickname that version had) – but it looks like a few things (not many) have changed. In 6.10 (AKA Edgy Eft) the Disks Manager is gone, but you can still use the Device Manager to figure out what disks you want to use to create your RAID. I still have two of these 160GB SATA Seagate drives that I’ll use for the sake of this example. Here’s a screen shot of the Device Manager, I’ve browsed to the first of the disks I’m planning on using, and you can see that it’s /dev/sda (screenshot, top right).
This screenshot also shows that my drives contain the Backup volume – I’m nuking this volume to create this RAID.
Now we open up the terminal, and get going. My drives are /dev/sda and /dev/sdb, so the first step is to use cfdisk to partition them:
daniel@ubuntu:~$ sudo cfdisk /dev/sda
daniel@ubuntu:~$ sudo cfdisk /dev/sdb
Running cfdisk opens a cursor based application that you need to use to create the partitions. I deleted all existing partitions, and then created a Primary partition that took up the entire disk. Then I set the Type to FD which is Linux Raid Autodetect.
Next we load the RAID module for RAID-1 (Mirror):
daniel@ubuntu:~$ sudo modprobe raid1After this, I opened up Device Manager again to see what the partitions had been called that we created on our disks. One of my partitions is /dev/sda1 and the other is /dev/sdb2. You can check out the screen shot below to see what I was looking at:
You can also notice from this screen that the Backup volume has indeed been nuked, and now we simply have Volume (linux_raid_member).
The next thing I want to do is run mdadm, but in my install of Ubuntu 6.10 it doesn’t exist, so we’ll install it:
daniel@ubuntu:~$ sudo apt-get install mdadmThat will spit out a bunch of stuff and eventually you should get the message:
* Starting RAID monitoring service mdadm —monitor [ ok ]Alright, now let’s run mdadm to create the RAID:
daniel@ubuntu:~$ sudo mdadm —create
/dev/md0 —level=1 —raid-devices=2 /dev/sda1 /dev/sdb1For me, I was prompted to confirm that I wanted to continue to create the array, because it looked like my disks were already a part of an array. I just pressed ‘y’ and carried on.
At this point, the RAID is being constructed, it’s not yet completed, even though you’ve been dumped back to the terminal. We can view the progress of the resyncing like so:
daniel@ubuntu:~$ sudo cat /proc/mdstat
Personalities : [raid1]md0 : active raid1 sdb1[1] sda1[0]
156288256 blocks [2/2] [UU]
[>....................] resync = 2.4%
(3886336/156288256) finish=52.6min speed=48201K/secunused devices: <none>
daniel@ubuntu:~$
So in 52.6 minutes we should be good to go. Now is your queue to grab me a Caramel Macchiato from Starbucks…Triple Grande, please.
Once the RAID is finished doing the resync, we need to create a file system on that bad boy. I’m going to use ext3, but you can go ahead and use whatever strikes your fancy.
daniel@ubuntu:~$ sudo mkfs.ext3 /dev/md0And voila! Once that’s finished, we should have a nice shiny file system that’s all RAIDified. Before we can actually do anything with it, we first need to mount it. I’m going to mount mine at /backup, but again, you can mount it however or wherever you see fit.
daniel@ubuntu:~$ sudo mkdir /backup
daniel@ubuntu:~$ sudo mount /dev/md0 /backup
Now with any luck, we should have 160GB of RAID goodness mounted at /backup, let’s check to see what we’ve got:
daniel@ubuntu:~$ df -k /dev/md0I would love to paste the result of the above command here, but the stupid terminal is not copying my selected text to the clipboard, but trust me when I say it tells us we have a nice ~160GB file system mounted at /backup.
Since we don’t want to have to remount the file system every time we reboot, we can add an entry to /etc/fstab to get it to mount at boot. As I’ve mentioned before, I’m not a Linux ninja by any stretch of the imagination, but if you read the man page for fstab and take a look at what’s in your current file, I’m confident you’ll easily be able to get it to mount the way you’d like. For me, I basically copied the line from my boot disk and changed /dev/hdc to /dev/md0 and also changed the last column (pass) from 1 to 2.
/dev/md0 /backup ext3 defaults,errors=remount-ro 0 2There you are, a newly updated entry on how to set up a nice software RAID in Edgy Eft (Ubuntu 6.10). Enjoy.
I’ve been really busy, so it’s taken some sweet time, but at long last I’ve been able to upgrade to SimpleLog 2.0 which Garrett Murray managed to push out the door. I redid all the colors, background, some of the fonts and the overall width of the content in my ongoing mantra to ‘mess with CSS’ more. The latest version also offers content and comment feeds, among other things, like a prettier admin interface.
DreamHost is continuing to aggravate me in new and special ways, none the least of which was deploying the new version of this site. I’ve got some space over at SliceHost that Nick has so nicely set up for us, but alas, I haven’t had the time or energy to get things moved over there yet.
I suppose deploying the new site isn’t a bad way to spend the afternoon after sampling a few pints with James at Pump Room Asia.
I’ve been meaning to comment as well about the relatively new and beautiful support for Ruby / Rails in both IntelliJ IDEA (screencasts here and here) and NetBeans (screencasts here and here, but I haven’t had time. It’ll have to wait for another day.
Don’t get me wrong, I love TextMate, but it ain’t no IDE.