Sunday, April 12, 2009

 

Start, Ruby, and me

Category: Programming Topic: Building tools



Ever since I heard Dave Thomas talk about it at a Spa (un-)conference in 2006, I've been a big fan of the programming language Ruby.

Perhaps that's partly because the first time I 'got' object-oriented programming was when I played around with Smalltalk, and Ruby reminds me of Smalltalk. But it's partly because Ruby comes with a library that makes writing small tools so easy. I'm thinking of the kind of tools that help me get computer work done more quickly and more easily.

Here's an example. Because of who my clients are, I use Windows. I'm a big fan of its start menu. I don't just have shortcuts to programs such as Firefox and Thunderbird; I have shortcuts to folders I often want to open, such as the folder called Aadvark, which is where I instruct applications to save files, so that I know where to find them.

(Aside: It's called Aadvark so that it appears near the beginning of where I keep almost all of my documents, in a folder called Filestore, which sits inside My Documents. I don't work directly in My Documents. I get too irritated. Windows gives me the facility to select an entry in Explorer by its first letter, but then names the folders within My Documents as My This and My That, so they all begin with 'm'. Aaaaagh!)

On the start menu, I also have shortcuts to Ruby programs that open several things, ready for me to start work on a task. For instance, when I have saved yet another movie or TV program to DVD, and want to add it to my database of DVDs, I want to open:

- the folder '.../Filestore/.../Lists/DVDs

- the Ruby application that allows me to add a DVD to the database, and then builds a new HTML index from it, so that family members don't have to browse the database directly

- 'My Computer', so that I can see what name I gave the DVD when I burned it

- the Internet Movie Database website, in case I want to look up details of a movie.

The Ruby program that does the opening for me uses Ruby's Win32OLE module, and is based around a two-line function:


def open(pathname)
  shell = WIN32OLE.new('Shell.Application')
  shell.ShellExecute(pathname, '', '', 'open', '')
end


For instance, the call open('My Computer') opens an Explorer window on My Computer. How easy is that?

If you are going to build tools to help you work, the effort you put into tool-building must be repaid (otherwise you're building the tools as a hobby). And with Ruby, the effort required to build tools is so low that I always find the effort is repaid.





<< Home

This page is powered by Blogger. Isn't yours?