Sunday, August 20, 2006

Unit tests are a newbie's best friend.

Contains all essential java nutrients?  Huh?Unit testing was a practice I picked up after years of programming, not because there is something difficult about it, but because I just didn't know. These days unit testing is the thing I do first in a language. It is the stick I use to poke at something new. For example, yesterday I was making my first foray into the Ruby/Rails world, specifically I was working with Active record. Here are the tests I wrote while playing with it.


require 'book'

class BookTest < Test::Unit::TestCase
def test_book_creation_works
war_and_peace = Book.new("title" => "War and Peace")
war_and_peace.save
mystery_book = Book.find_first "title = 'War and Peace'"
assert war_and_peace.title == mystery_book.title
end

def test_unit_tests_are_independent
mystery_book = Book.find_first "title = 'War and Peace'"
assert mystery_book == nil
end

def test_book_requires_a_title
bitter_ejb = Book.new
assert !bitter_ejb.save
end
end


It is too bad that a tool this useful and simple isn't something recommended to beginners early on. I am picturing programming 101 being test driven from now on. Perhaps it is time to retire "Hello, World!" in favor of an assertion. assertEquals("Hello, World!", atom.greeting()); A new programmer's first task will be a green bar, not a println.

Monday, August 14, 2006

Google sets

http://labs.google.com/sets

Return to Javaland

Sequels are usually a bad idea.
Bad java.
A few months back I was reading a blog entry by Darren Hobbs entitled, A bad citizen in Javaland. It is a really creative description of a day in the life of an object. This particular object is a bad citizen because it violates some basic rules about good object oriented code. For example, when the object climbs on top of a car like it is a motorcycle it is trying to cast an abstract object to the wrong concrete type. When the object reaches under the hood, grabs the engine and reaches into the engine to grab the starter. The object is violating encapsulation and not using the given interface, in this case the ignition switch, to start the car.

Thinking about good objects vs. bad, it strikes me that to a certain extent an object can only be as good as the classes it depends on. Just like adding one good citizen to a maximum security prison does not a utopia make, one beautiful and well tested class will not make a large codebase much better (although you have to start somewhere). As I considered relationships and dependencies I went back to Darren's excellent description of Javaland, and I couldn't help but try my hand at writing a sequel. Here goes. Sorry Darren.

Wednesday, August 9, 2006

Buildix: Garage Band Agile Development

Buildix: the geek equivalent of having the wall of sound in your garage.
Buildix = Rock'n'Roll
You say you can write a bitchin hello world application? Your operating system has recently come down with a kernel? You don't know what IDE stands for, but your computer has just developed one of those too? Hello there Mr. or Mrs. Rock$tar! It sounds like you are ready to tackle your first software project. But wait. Don't be like so many other clueless hacks out there. If you are going to do this, do it right. Have some pride. Distinguish yourself. "How?" you ask. Simple, make your first software project an Agile software project. C'mon... Everyone's doing it. And besides there is a new way to get started, and it is easier than power chords on a Fender Squire. So gas up the van, gather up your band, cinch up those leather pants, and prepare to make rock, er, software history.

I just downloaded Buildix which is a Debian based distro specifically for running agile projects. You can go from zero to a finished CruiseControl build in under five minutes! Not only is it an easy install, but Buildix is also a live CD which is nice for doubting thomases who want to try before they buy. Don't sweat the download either. It is pretty light, weighing in at just over 350 megs. All of this is great news for aspiring Agile Rock$tars everywhere. Even if you are faking it, at least you look good doing it. So go check out the Wikipedia page on Buildix I just created. Download the ISO, and turn the volume up to eleven. Rock on!