Monday 2 July 2012

RUBY BABY

Dick Pountain/13 July 2006/14:46/Idealog 144

I'd begun to think that my programming days were over for good. Though I've never actually worked as a professional developer, I have written a few programs for money over the years (one was an MS-DOS emulator that wound up in the radio telephones they used while drilling the Channel Tunnel, another was a database of the world's greatest ikat textiles, for a collector in New York). What I have done is learned and written about a lot of programming languages - 21 at the last count, many of them experimental, some of them frankly off-the-wall. But mostly I program just for pleasure (yes, there is pleasure, rather like that of chess), or to write small utilities I need (say to change the bloody phone codes again), or to implement some algorithm I've come across in my reading. For example the book I mentioned here last month, Philip Ball's 'Critical Mass', suggested dozens of programs I'd like to write.

Finding a language nimble enough to fit this usage profile is becoming less and less easy. Once I used Forth, then Lisp, then Turbo Pascal, Delphi, Visual Basic and most recently Python. Several of these failed the transition to Windows, while others made it but grew bloated in the process. I need something small, fast to write and preferably interactive (Turbo Pascal compiled so fast and had an IDE that made it feel interactive, ditto with VB). I'm also overly fastidious about language features and syntax, almost to the point of obsessive/compulsive disease: I detest the syntax of C and C++ so much that I can't bring myself to use languages like Java that imitate them. I'm deeply committed to both object-oriented and functional programming styles, and can't get on with any language that doesn't support lists (I wrote my own for VB). 

Delphi and Visual Basic grew too bloated for me at about versions 3 and 4 respectively, but I was temporarily excited recently when Microsoft announced Visual Basic Express - I tried installing the version distributed with PC Pro, only to discover it had time-expired, and somehow I haven't felt motivated to buy one yet. Python entertained me for about a year but I gradually started to get irritated by the Unix-ness of it, the messy installation and path handling, its TTY-ish IO and lack of any really sanitary interface to Windows. Around that time, after finishing a matrix arithmetic package in Python I started to run out of things I wanted to program, and even, whisper it low, become bored with programming itself.

Then something came along completely out of left-field that's rejuvenated my flagging programmer's taste-buds, or to mix metaphors in a most perverse way, acted like programmer's Viagra. That something, believe it or not, was Google SketchUp. As with Flickr which I wrote about here recently, I have RWC columnist Tom Arah to blame for this one - he made it sound so interesting in his column that I downloaded all 19MB of it and started to play. As a simple 3D authoring package SketchUp is quite outstanding: anyone can start to create 3D models within minutes without the horrendous navigation problems that usually beset such software. SketchUp's clever inference engine second-guesses what you're trying to achieve and saves you from flailing around along three different axes to place things where you want them. To be sure it's limited to largely rectilinear, building-shaped objects, but then it was intended for architects.

Very soon I'd created a 3D model of my Italian house, complete with surrounding terrain and trees, and rendered in surprisingly realistic stone and terra-cotta tile textures. It was while flying around this model that I noticed the fateful item on the Window menu called 'Ruby Console'. I selected it, instinctively typed in "2+2" to the blank window that opened, and very soon was hooked. I'd vaguely heard of the Ruby language, that it was an object-oriented scripting language something like Python, but mostly in the context of its web authoring framework Ruby On Rails. It turns out that SketchUp includes a full implementation of Ruby (without all the libraries though) as its scripting language, with an API that lets you into the very guts of the 3D engine. I use TextPad as my editor via a file I call "scratchpad.rb" that SketchUp loads automatically on startup.  

Ruby comes pretty close to being my ideal language, with a beautifully clear syntax and excellent features that include very deep object-orientation, concurrency and pattern matching: its "array" type can act like a list, a queue, a stack, or whatever you want. Ruby's Japanese author Yukihiro "Matz" Matsumoto describes his aim as a 'least surprise' language, and indeed I found that time after time I could just guess how some construct worked (with a little help from the ".methods" method). I did consider downloading the full open-source version of Ruby, but then thought again: one of the reasons I wanted to start programming again was to try some simulations from 'Critical Mass' that involve movements of people, and what better environment to do that in than one that gives you 3D for free? I now have crowds of little people running around inside a 3D Pisa Cathedral, and all in around 200 lines of code. I'm thinking of calling them Mobjects...

No comments:

Post a Comment

SOCIAL UNEASE

Dick Pountain /Idealog 350/ 07 Sep 2023 10:58 Ten years ago this column might have listed a handful of online apps that assist my everyday...