09th Dec 2007 by Mark Turansky

Horses for courses

Filed under Filed under Code Hints, Engineering

A friend/programmer/co-worker of mine recently bemoaned my use of the term “pick the right tool for the job.” Apparently, he thinks it’s a tired metaphor. And so in deference to my friend, this blog entry is about choosing the right horse for the course.

Some horses are mudders, some are good at short-distance sprints, still others are the ones you want for the long race. If you’re eying the race’s purse, you choose the right horse for the course.

So, how do you choose the right horse? I’m guessing it has something to do with experience, breadth of knowledge, and understanding when a functional program makes more sense than an imperative one or knowing when a script is better than a fully engineered OO implementation. Here’s an example to fan the Java vs. Python flames.

Not too long ago, in my previous life working for a consulting company, I wrote a small Java application to monitor our many web applications. The requirements were simple: the server page should return “OK” (text/plain) else the contents of the entire page would be mailed to a list of interested recipients. This technique allows a developer to put whatever test they want in their server page (database connectivity, unit tests, whatever) knowing that any exception they write to the page would be mailed to them.

Not hard, right? Easy implementation? It was both times I wrote it, but one of them was a much better horse for the course.

The configuration file in Java was XML, natch, which required an XSD. The XSD required Castor (or its equivalent) to generate bindings for the XML. The Main program was well factored in that each class did one thing well. As a result, I had a class to poll a site, one of load the configuration, a class to send email, etc. Between Main and classes from Castor, I was up to a dozen .java files. Main, of course, required libraries (Castor, mail.jar, activation.jar, etc.), and those libraries required a script (.cmd in our case) to load them all onto the classpath. Oh, let’s not forget about building with Ant. Add a build file to the heap.

It worked, but damn, that’s a lot of files and jars and complexity for a simple monitoring program!

I rewrote it in Python in less than 40 lines of code. Two files. There are more comment lines than executable code.

Choose the right horse for the course. Occam’s Razor says the 40 line solution is the right one, but you can decide for yourself.

Here’s the python program and configuration file.

Many developers learn one or two mainstream languages and always run their favorite horse, irrespective of course. The best developers will be those that love learning new languages and techniques. I’m a better Java programmer today because of what I’ve learned from Python. I’m a better web developer today because of what I’ve learned from Ruby on Rails.

Learn more. Broaden your horizons. Try new things and new styles of development. Learn to pick the best horse for the course. Always use the right tool for the job.

What's next? CommentsLeave a comment Digg it Save This Page

One Response to “Horses for courses”

  1. Jason McDonald Says:

    I never knew you were an equestrian…

    I will take credit for the dislike of the term “right tool for the right job”, however dislike of the term is where it ends. Mark is correct in his explanation of using the right horse for the course - the bitter taste from the phrase simply comes from too many people using it too many times as an excuse.

    There are many times in my career I have heard people say “its the right tool for the job” simply because:

    1. They were too lazy to research other tools.

    2. They were too new/ignorant to understand the full use case for the tool/code/app in question.

    3. It was a cool technology and they just wanted to use it.

    Because of the above reasons this term has quickly become cliche and is often offered up as an excuse by those that fall into one of the above categories.

    Simply put, the right tool for the right job is a good credo and is well worth following. But with all things, when it becomes a mainstream term it often becomes diluted and loses much of its core meaning.

Leave a Reply