Test-Driven

I started reading Kent Beck's Test-Driven Development: By Example over the weekend.  Tim Bray mentioned the book a while back and his impression of TDD differed from mine so I figured I was overlooking something.  Boy, I sure was.

I thought TDD (Test-Driven Development) was just development with a strong emphasis on tests.  It's more than that.  What threw me off was the word 'development' which encompasses the entire development process including design, implemention, evolution, etc.  The core gem of an idea behind TDD impacts the design phase most heavily and it's uncovered in rather tedious detail by Kent Beck.  Tedious yet startling is what I felt.

The simple idea is this:

Design software by writing tests first.

By 'software', I mean services, frameworks, modules, components, and objects.

Since tests are written before the module being tested is written, the experience of writing of the test drives the module's designing process.  More importantly, you are looking at the API, of the module being designed, from the API client's perspective.  Net result is higher quality API design.

While TDD during the design process is enough of a benefit for engineers to put into use immediately, TDD has problems because test cases are software and there are maintenance cost associated with them.  Having a tool like Eclipse helps but much more is needed to help the engineers document the tests, keep track of them, and reuse as needed.

I think a visual tool that lets engineers drag and drop tests into test suites for various purposes like release testing, runtime testing, diagnostic testing is essential.  TDD also encourages refactoring through out the development process which calls for more flexible source control system than CVS.

TDD Experience:

It ain't real until it's real so I put TDD into practice to write a small module.  The experience is definitely different than the usual way of designing and implementing software.  Deep thoughts are pushed to the background where it continues to churn while I am hacking and slashing in frenzy to make the JUnit bar turn green.  Everytime the bar turns green, deep thoughts surfaced and I dutifully jotted them down before I dived back in.  It felt very much like the way I felt while playing an intense video game.

To get started on a module, I just created a separate Java project using Eclipse because I could just drag and drop classes into the main project when I am done and Eclipse takes care of all the refactoring automatically.  I then added an empty class which represents one of the objects in the module I am writing.  No heavy thinking there.  Just something to get started with and refactor later.  I should have created a JUnit test case first, but it doesn't really make a big difference at this phrase.

I then created a test case for the classes and filled it in with a bunch of TODOs.  Eclipse picks up those TODOs and populated the Problems view so I can easily keep track of all the outstanding tasks in this TDD run, sort of like the missions view in RPG games that lists all the tasks one has to perform to clear an area.

I replaced the first TODOs with code to instantiate the object and then made an method call.  Eclipse flagged the line immediately because the method didn't exist.  I clicked on the flag and selected a QuickFix command that told Eclipse to create the method.  Wham.  It's there ready to be filled in.  Since I just want the bar green, I made it return a constant string value which should have been fetched from elsewhere.  Back in the test case, I wrote an assert statement that checked for the value.  I then rigth-clicked on the test case and selected Run > JUnit Test.  Woohoo.  I see a green bar!

This process was repeated at a furious pace over a couple of hours, during which I continue to added more TODO items and change TODO items into DONE status until there were all DONE.  Through it all, Java classes and JUnit test cases were added, removed or refactored.  In the end, I got a nice module with reasonably easy to use API and a set of test cases.  Whew.  What a workout.

Is TDD effective?  I don't think it's for everyone just as not everyone enjoys playing video games.  But it was productive for me.  I got more immersed into the design than I normally would have and finished with a more polished end product earlier than I would have.  Usually, I would render a first cut of a design and then sit on it for a few hours to a few days to get the kinks out.  With TDD, I went through tens of iterations per hour.  So the speed of development is definitely not a concern for TDD although I did feel a bit of adrenaline withdrawl symtoms at the end of it.

Will I do it again?  You bet.  I have to get to the next level, don't I? 🙂

Update:

I thought I should make it clear that I am not a proponent of TDD and I am not recommending it to everyone.  TDD is just a new tool I am adding to my bag of tricks because I find it useful and I enjoy the experience.  As I wrote above, I don't think everyone will find TDD useful.  It's up to you whether decide to try TDD or not.  If current style of development works for you, I don't see why you should look for something else.

Eclipse RCP: The Early Days

I played with Eclipse 3.0's new RCP (Rich Client Platform) support which allows you to build client software using the same engine that drives Eclipse 3.0 IDE.  While one could have build a client using just SWT, RCP allows you to reuse many of the Eclipse plugins in your application.

In essence, RCP allows you to easily repackage Eclipse 3.0 IDE such that it only has the features you want presented in the way you want.  Dependencies between plugins will complicate and bloat your RCP application, but I am expecting many RCP-ready plugins to be available soon so this is not a big problem.

The big problem, for now, is the lack of RCP tools and documentations.  Eclipse 3.0 has very little built-in tools to help you create RCP applications.  For example, Export Plugins feature to export a test RCP app but it didn't automatically include the necessary plugins.  So I had to write an Ant script to do that.  But then my sighs of annoyance turned to urghs of disgust when Eclipse deleted the Ant file when I ran the Export Plugins again.

I had a lot of trouble running and debugging the RCP app too.  I followed the instructions in the RCP tutorial exactly, but the startup code kept complaining that it couldn't find the application.  Looks like I'll have to dig into the plugin startup code and understand it more throughly.

In conclusion, I think RCP is wonderful but it's still a bit early.  Wait a few more months before diving in unless you can't afford to wait.

Destroy Troy

When I wake up I usually find some interesting remains in my mind.  It's as if the brain forgot to flush the cache when I awake.  This morning it was the thought that the word 'destroy' originated from the fall of Troy.  So to destroy is to suffer the same fate as the city of Troy did.

Is this true?  Dictionaries I looked up didn't list Troy as the origin of the word.  Searching Google returns many pages that mention the city of Troy and the word destory together yet none seems to suggest there there might be a closer relationship between the word and the name.

Seems unlikely though.  The concept of destruction has a long history and, while the destruction of Troy took place long time ago, use of the word 'destroy' to mean 'do the same as what was done to Troy' would require a lot of story telling.

A: Destroy that city by nightfall!
B: Do what?
A: Destroy!  Turn it into rubble like Troy.
B: Troy?  What's that?
A: *sigh* You never heard about Troy?  Giant Horse?
B: Uh, no.  Why don't you tell us?

More likely, the word is related to the word 'destruction', removal of structures, but it's fun to play with words anyway.

Eclipse C++ Development Tools 2.0 Released

Version 2.0 of the C++ Development Tools (CDT) which turns Eclipse into a C and C++ development environment was released on July 2nd although there is no evidence of that at the Eclipse CDT page yet.

You can either download the binaries from here:

http://download.eclipse.org/tools/cdt/releases/new/

or install it via Eclipse update tool using the following URL:

http://update.eclipse.org/tools/cdt/releases/new

A Visit to Fry’s

It's been a while since I have been to Fry's but I needed to get some gears today.

Wi-Fi stuff – Annoyances of being wire-bound finally got to me.  So I picked up some Wi-Fi PCMCIA cards and a Wi-Fi router/firewall.  It's amazing how cheap the stuff is now.  I paid $29 per Wi-Fi cards and $49 for the Wi-Fi router/firewall, both made by D-Link.  They were actually $49 and $69 respectively, but I lucked out and got $20 rebates on each of them.

External USB hard disk – I didn't want the hassle of upgrading the internal hard drive so the only remaining choice was an external hard disk.  I went with Maxtor One Touch 250G which was priced at $279.  Isn't it annoying that external drives cost about $100 more than the internal drives?  Someone must have read my mind because they charged me only $179 for the drive when I got to the counter.  Weird but I wasn't going to argue with them to charge me more, so I was smiling on the way out.  Heh.

I also had to get a USB 2.0 PCMCIA card for the laptop because my Dell laptop only had USB 1.1 support.

Now it's time for a bit of ranting.  I can't use Wi-Fi and USB 2.0 at the same time because both the Wi-Fi PCMCIA card and the USB 2.0 PCMCIA card has bulb-like ends.  They are all right if only one card is like that but you can't insert two such cards at the same time because they both extrude in the same direction (normally up).  If different direction is problematic they they should have at least made one card types longer.

Update:

I guess you get what you paid for.  I got Wi-Fi working but when I started looking around the D-Link router admin console to increase security, I found that D-Link is rather lacking.  For example, I found no way to restrict access to a handful of MAC and WPA didn't seem to work.  Windows Wi-Fi control panel being confusing didn't help either.

I wonder if NetGear is any better.