Everyday Scripting with Ruby - Book Review

June 24, 2007

I recently finished Everyday Scripting with Ruby written by Brian Marick

Apart from using the pickaxe as a reference this is the first book on pure ruby that I have read. One big advantage that this book has is it uses ruby in a different context instead of the “rails way� that I am used to.

Over the last year I have been writing more and more scripts; mostly in Ruby and Bash. I have written everything from basic copy scripts to a more complicated website crawler called the harvester. I wont speak any more about the harvester as I am not proud of its application! It was great to read a book about the black art of scripting and get a strong grasp of how Ruby can be utilised in this context.

I thoroughly recommend getting this book and reading it cover to cover. The book starts easy then progresses in difficulty so is more of a cover to cover read than a reference. Apart from the chapter on regular expressions which is the most detailed description of ruby regular expressions I have seen to date.

TDD

Brian also mentions TDD very early on and manages to do well to enforce it throughout the book. I definitely go for the TDD approach when developing rails applications and plugins (wrote my first last week!) but have yet to use it for script development.

I am of the mind that TDD is great if you go as far as to start extracting methods to a class. If however, you are just writing a simple single stream script as I mostly do, it is not worthwhile writing tests for something simple and throw-away.

Driving the Browser

(http://www.openqa.org/selenium/)
There is an interesting section in browser control which I did not know about. There is Watir and Selenium which can be used to control browsers from within ruby.

There is also the mechanize ruby gem which can be used to build simple crawlers. This is interesting when you think about what is possible. I remember back in the day Alistair Burns and I wrote a bot for planetarion which would login every few hours and then send an email to your phone if you were under attack. We wrote it in PHP4 and it was a fairly dirty script. Nowadays you could do the same in ruby in an embarrassingly little amount of lines.

Modules, Classes and Monkey Patching

There is a great description of the above and when you should do each. Shoud what you are writing be a module or a class. Do you just monkey patch to solve the problem? All is explained here.

Top marks for this book. Buy it if you can.