Skip to main content

The Problem with Scripting

Posted by mikel on January 3, 2005 at 8:21 AM PST

A few days ago, I needed to write a program that was essentially a variant of the well-known UNIX diff. I had to find out which lines had been added and deted between two versions of a file--the trick (which made diff inapplicable) was that the order of the lines had been changed.

Well, I'd been wanting an excuse to learn Ruby for some time, but the more I thought about it--I could write this sucker in Java in a few minutes, and be done with it. I needed it it RIGHT NOW. I didn't want to have get stuck in the semantics of a new language.

Bottom line--I still have to learn Ruby. I realized I could (and did) write the program in less time than it would have taken me to find one of my Ruby books. (Sorry, Dave and Andy--it's still on the shelf...) It weighs in at around 25 lines, with somewhat more exception handling than I usually bother to do.

So I really have to ask: what's the "scripting language mystique" all about? You don't have to run javac? Rubbish--I don't believe that's a big issue. You don't have to write declarations? Bull--writing declarations means (to me) that it's easier to debug misspelled variable names. That's a HUGE time saver. As Brett McLaughlin has often said, "whenever you can get the compiler to do the debugging, it's a win." Is it that scripting languages are better "glue" languages for calling UNIX utilities and other external programs? Well, I don't see why it's so difficult to call Runtime.exec(). The fact is--if you have some documentation, you can use Java to call into the guts of other Java programs, not just their external command-line interfaces. That's some pretty powerful glue. If you understand reflection or have been watching what's going on with lightweight containers like Spring, you've got real computation superglue.

Or is it that this could have been written in fewer lines? I'm sure this program could have been compressed into a single line of Perl, or maybe a dozen lines of Python. Sorry, I just don't see "number of lines" as a good metric of anything. When I was in high school, I loved APL because just about anything could be compressed into a single, inscrutable line. I didn't believe in comments then, either. When I was a child, I thought as a child... I admit to being biased--as an O'Reilly editor, I read much more code than I write. So being readable (and I think Java is very readable) is very valueable to me.

The really sad thing is: there's another programming task I need to do. I've got to change a fairly simple line-oriented file format into a sort of bastardized xml-like format. It's trivial in Java. I've really set this task aside as 'the program I'll write in Ruby'. But, really--in Java, it's 10 minutes of work. And I'm tired of setting it aside.

Ultimately, the only criterion is getting the job done.

Related Topics >>