25 June 2012

Test-Driven Development as a Design and Learning Technique - Introduction


The company for whom I'm now working is a Ruby on Rails shop, and prior to starting with them I hadn't done much more than Hello World in Ruby and its equivalent in Rails.  So, once I started I decided to use TDD as an approach and tool for learning the Ruby language and Rails framework, as well as a driver for everything I needed from an environmental perspective.  I wouldn't add or start anything new until I had a concrete need in the form of a failing test!

One of the first things I did with the company was to run a TDD demonstration session using the Prime Factors kata, which required me to learn a little Ruby and test-unit, and I used a combination of text editor and the command line on my Mac.  I had already done that particular kata loads of times in Java with JUnit, so it was quite straightforward to implement using Ruby.  Did I write the best Ruby code for the exercise?  Perhaps not, but I'm sure over time I'll improve.

So, I was past Hello World, but now needed more.

My next step was to do something 'real'.  I use public transit to get to work, since it's actually quicker, cheaper and less stressful than driving to the location in which I work.  The local transit authority recently opened up a REST API for obtaining live information about bus trips for specific routes and stops, and it sounded like something interesting to play with that had some concrete value, so I dug in.

I had a vision of an application that could take a geographic location, find the nearest bus stops within a given range, and give me a list of bus arrivals at those stops.  Ultimately, the system would be driven from Android and iOS apps using the Location Services on the device to provide the current location of the user.  I also envisioned having the user be able to select favourite bus routes and stops in order to filter the list to show only the buses that were of interest to the user.  I'm sure someone else has already done something similar, but I wasn't trying to build a system for commercial purposes.  The idea here is to learn while creating something with a real world application!

Here's a high-level view of the system:

This system appealed to me because it was going to slice through many areas that were new for me.  I had to learn the Ruby language sufficiently to retrieve, process and push data to a client of some sort.  I also have done nothing beyond Hello World in Android, and nothing at all in iOS.  This system provided many dark corners in which I could shine a light, and get my hands dirty again in code!

Again, though, the whole philosophy I will follow is to take a TDD approach - nothing new added from a code, library, environment or tool perspective until required by a failing test!

Stay tuned for more about my first steps into this adventure!

1 comment:

AlanD said...

I like this approach. Practical Agility indeed!