Extra Credit

Like most Engineers I occasionally get inspired to pursue extra-curricular technical projects. Over the years, they’ve ranged from simply learning a new language/framework, to hacking around with circuits and micro-controllers to writing (sometimes) useful little applications. Most of the time, there’s nothing interesting to blog about. I think my current project is different and might be worth sharing.

Briefly, the most recent project cycle started with two disconnected attempts:

1) Lisp: Frequently, when you read about the merits of a new language, you find people claiming “…language x is a lot like Lisp…” The pointer back to Lisp is somehow supposed to add some legitimacy to language x. So, with all these people holding Lisp up as the gold standard, how come they don’t code in it? Having recently spent time coding in Python and Ruby, I was curious to revisit Lisp as it had been a long time since I did anything more complex then add lines to a .emacs file; I decided to give Common Lisp a whirl.

2) Algorithms: From time to time, I still step in some CS pothole that neither experience nor education helps me with. So, in hopes of filling this gap and learning something interesting I decided to take on the project of working my way through the textbook “Introduction to Algorithms” (Cormen, Leiserson, Rivest, Stein / MIT Press).

Giving up scarce night and weekend hours on a project needs to produce something that you value (a lot) if you’re going to keep working on it. Many projects die before completion because you realize, after the initial excitement wears off, that making that LED flash red then green (Whoo Hoo! Errr… that’s it? Really? Hmm…) might not be worth punting the myriad other things you might do with you paltry-few free hours.

Learning CL was proving to be fun but had little value in a vacuum and was unlikely to be the language used on any commercial project I’d (ever?) be involved in. On the algorithms side, my approach - reading the chapters then doing the exercises and problems - was uninspired and moving along at a painfully slow pace. While I really valued this activity, it was hard to be excited about.

So, both projects faced individual defeat and had begun to gather dust until about a month ago when they were jointly resurrected. In short, I abandoned grinding through all the abstract proofy stuff in the algorithms book and punted on worrying that I had not mastered all the esoteric (weird…) features of CL and just started implementing algorithms from the book in CL.

This was fun.

In addition to making the textbook material more tractable, coding algorithms in Lisp is a good exercise for learning the language; it’s easier to write “lispy” code (e.g., adopt a more functional style) when implementing pure algorithms than it is when implement something more “practical” (like a PIM or whatever) that requires grungy I/O, error handling, etc.

So, I’m hoping this approach is sustainable; the algorithms are interesting and do interesting things; the language is interesting and useful for implementing the interesting algorithms; the dry proofs are much more digestible when they’re mixed in with the coding exercise.

In addition, the “bites” seem to be a good size to stave off stagnation - I can get through an algorithm (read, code, go back and understand the math/proofs) in anywhere from a couple of hours to a couple of days. You don’t get bogged down and you can walk away from the project for a while then still come back and not have to recover a lot of context - you’re never be more than a few days into a task so reengaging after a week/month away is not a big deal.

Finally, and probably most importantly, each new chunk is fun and I’ve been looking forward to doing them.

So maybe this will work or maybe I’ll sputter as the algorithms get more complex or the novelty of the whole thing wears off. I’m optimistic, though, that this is a winning combination (code and learn…); I know I did better in lab courses in school then just cranking problem sets.


So the reason that I’m sharing this (and not the Blinky LED Micro-Controller Project) is that I think sharpening up your algorithm skills is valuable and that approaching it as a lab project with an interesting language element (learning CL) may make the medicine considerably easier to swallow then just slogging your way through a book with a mechanical pencil and notebook.

If it works for me, it might be a useful approach for someone else.

As I go along, I’ll post code and notes; it may be interesting/useful to someone else and someone with real Lisp kung-fu may feel compelled to comment on how I could/should have implemented the algorithms.

And finally, I admit that I have an ulterior motive for posting my progress; if I post, I hope that, perhaps, people will periodically ask “so how’s that algorithms project going?” which will shame me into picking up the effort again when I invariable get distracted by some other shiny thing.

3 Comments so far

  1. Software Physics » Merge Sort on December 13th, 2008

    [...] As the first commenter to this post pointed out, I’m not a Lisp expert. As I mentioned here I’m using this exercise, in part, as a way to learn the language. Also, one of the attractions of [...]

  2. Software Physics » Heap Sort on January 16th, 2009

    [...] have been occupying my attention for the past couple of weeks but, fear not, I’m still pursuing my algorithms project. Next up on the agenda is Heap [...]

  3. Marc Linster on February 8th, 2009

    Having worked for 8 years in Lisp (Common Lisp, LeLisp and Symbolics Genera), I can understand the fascination of focusing purely on the algorithm, with very little concern about memory, cost of recursion etc.

    I just started a bigger project in C#, after a 8 year hiatus in ‘management’ — and I am amazed how many of the Lisp concepts can now be applied in a rather painless way — but I still don’t dare using recursion.

    Enjoyed reading the blog. How about posting code snippets?

    Cheers, Marc

Leave a reply