Typo, typo, how I love thee

by Suw on December 29, 2006

I haven't had a chance to look at my Ruby on Rails for a few weeks, but finally on Wednesday I had a few hours to play with it. I had left my charger in the suitcase that Kevin had by his desk at work, though, so my window of opportunity would last only as long as my battery.
The last time I worked on my RoR, I ended up with an unexpected result. The book I'm working through, Agile Web Development with Rails, has you make a web shop, and I'd got to the bit where I was implementing the shopping cart function. I went through a ton of coding, but when it came time to test I got an unexpected result – the shop page failed to show any products, just the 'Show my cart' link. I was expecting to see a list of products with the 'Show my cart' link at the bottom.
I ran out of time and had to leave it, but coming back to it this time round, it still wasn't clear what the problem was. The book's publishers provide you with a bunch of files that show you what the code should look like at each stage of development. Now, I could cut and paste the code, but I don't because that way I wouldn't learn anything. Instead, I type it in from the book, and use the source files as a reference in the event of anything going wrong. Of course, things go wrong regularly, because there is always a typo somewhere.
I sat and pored over the code, file by file, line by line. Fixed a couple of typos, but neither of them actually fixed the problem (although I'm sure they fixed other problems that had yet to manifest themselves). I was starting to feel really frustrated, as my battery was not going to last long, and I wanted to actually make progress, not just hit my head against a brick wall for two hours.
I compared the code to the code in the source files, and to the code in the book, but still nothing. Then, going back step by step over what I had done, I noticed one little action taken in Terminal (i.e. at the command line):
drop table if exists line_items;
create table line_items […]

D'oh! This command deletes the old table called 'line_items' if it exists and replaces it with a new, empty one. Suddenly, a moment of clarity: the store front wasn't displaying the products because I had deleted them all! In fact, there's even a footnote on page 85 which says “If you don't see a list of products, you'll need to go back to the administration section of the application and add some.”
Oh dear. Note to self: Read the footnotes.
Anyway, progress after that was good, despite further typos. I made it all the way to the end of Chapter 8, and this afternoon I'm going to have a stab at Chapter 9. I'm still really just doing what I'm told in the book, but patterns of meaning are starting to coalesce out in my mind. I'm not sure I could yet create an application from first principles, but I'm starting to generalise out rules from what I'm doing which will, in due course, give me my much needed first principles.
Besides all that, it's actually a lot of fun. I can't wait til I have a bit more time on my hands to work on this more regularly.

Anonymous January 4, 2007 at 2:22 pm

I'm fond of telling colleagues that, in software development, if a problem occurs, when someone says “no-one could have been so stupid as to do X”, then it's practically guaranteed that they've been stupid enough to do X.

Comments on this entry are closed.

Previous post:

Next post: