Following the Rails

Like me, Christian Neukirchen has recently been making his first advances into Rails development. Also like me, he’s a Rubyist from way back, unlike a lot of people who have come to Ruby via Rails.

My practical experience of Rails began a few weeks ago, when I started my new job: before then, I had only glanced at the successive releases of Rails, but hadn’t had any reason to delve any deeper into actually using it.

My experience so far has actually borne out my initial impressions: Rails includes a lot of features to facilitate some of the more mundane aspects of web development, but it is not the universal panacea it’s sometimes painted as. That shouldn’t be taken as a negative comment, but just a reflection of the fact that writing a complex app is still complex no matter how you do it. What Rails provides is a good starting point, especially with respect to MVC separation, test-driven development, and automation of development tasks. It’s also probably useful in forcing some better practices on people who have used messier development techniques in the past.

Christian writes:

The second biggest problem is fighting with ActiveRecord; in fact, I think all my problems so far can be reduced to wrong use of ActiveRecord. I just hope we will get along better together in the future. (Once you got it to work, it’s pretty nice, of course.) Maybe my database schema was a bit too difficult for a first use. (Featuring self-referential entries etc.)

I’d agree with this. In fact, I’ve found ActiveRecord to be the hardest thing to use. Part of that is, I think, due to the so-called ‘impedance mismatch’ that’s probably inevitable when mapping between objects and SQL. I find myself knowing exactly what I want to do, and how I’d do it in SQL, but working out the ActiveRecord way is a bit harder. SQL can be unnecessarily complex and seemingly inconsistent, but ActiveRecord has plenty of surprises of its own—and many undocumented capabilities. It’s a frustrating process to learn them, sometimes.

I also think that there’s one big danger in ActiveRecord, but it’s one that is not actually inherent to the library itself. Because of the object-oriented syntax, it becomes natural to perform actions by chaining methods. In one respect, that’s excellent: it’s readable, and the intent is clear. On the downside, however, the differences in efficiency can become profound when the number of objects is large: in other words, it’s not so scalable.

In fact, just such a problem cropped up at work yesterday. The latest revision died under production loads, and I had to dig through the intermediate changesets since the previous release to find what was causing the problem. I’m not sure yet, but I think that a similar piece of code to the first example above was the cause. (We haven’t had a chance to verify it yet.) An item-counting method had been changed from an SQL query to a more Rubyish manner. The tests didn’t catch it, because it still worked, and they weren’t checking for speed or memory usage.

There are a couple of lessons, really. First, even if you abstract database operations into objects, it doesn’t necessarily get easier: some understanding of the underlying technology’s strengths and weaknesses is invaluable. Second, tests will only test what you thought to test for!

That’s not chicken!

I love this menu for a South London pizza delivery place:

A none-too-reassuring note advises us that their chicken curry contains real chicken (and I very much doubt that they really hold a trademark on ‘Curry House’):

However, the real gem is the randomly-chosen Chinese character they’ve chosen to decorate the background of the list with. It means horse.

I know that horse is indeed an unexceptional foodstuff in parts of the world—I’ve eaten it myself on numerous occasions, and I’m rather fond of it—but it raises a few eyebrows in England. In the context of the note about real chicken above, it also raises the question of exactly which meats they are using in the other dishes!

I’m back!

With the exception of a couple of sets of photos (which I can easily replace), I’ve been able to extract everything essential from the image of the crashed disk.

To recap, my hosting company deleted everything on the backup server without telling me, and when there was a hard disk failure on the actual server a few days later, everything was gone. I did have backups from much earlier, but it would have been a lot of effort to replicate everything from that.

Fortunately, they managed to recover the original hard disk image, and the only unreadable files so far have been unimportant ones.

If you find something broken, please let me know below!

Are we nearly there yet?

US President George W Bush, May 2003:

Major combat operations in Iraq have ended. In the battle of Iraq, the United States and our allies have prevailed. And now our coalition is engaged in securing and reconstructing that country.

US President George W Bush, December 2005:

Our forces in Iraq are on the road to victory – and that is the road that will take them home.

Any additional comment would be superfluous.

Hot drinks garbage

I do sometimes question whether computerised tills are really labour-saving devices. It took the man at the newsagent’s some time to ring up the correct code for the jug of milk I picked up this morning. When he eventually found it, here’s what came up on the display:

Hot drinks (garbage 0.99

I was a little startled and amused, but he assured me that it was what they used for all the items that didn’t fit into one of the regular categories. Kind of defeats the purpose, though, doesn’t it?

At least the price was correct, and the hot drinks garbage tasted fine.

Why don’t you know?!

I had to go to pick up a parcel that I’d missed; fortunately, the local collection office is only five minutes’ walk from here, so it’s no great inconvenience. However, the irate man in front of me delayed me a little—and also provided everyone with some amusement:

—Where is my parcel?
—I don’t know.
—I came here yesterday, and your colleague told me that it should be here today.
—It should be, but it isn’t.
—So where is it, then?
—I don’t know. Royal Mail delivers a million items every day; I don’t know where every one is.
—Well, whose fault is it that it isn’t here?
—I don’t know!
—Why don’t you know?!
—I just don’t!
—Who is the manager here?
—There isn’t one: we’re just a collection depot.
—So who is in charge?
—The SE1 Sorting Office.
—Do they know where my parcel is?
—I don’t know.

The conversation continued in this manner for a few minutes longer, as the angry customer asked the same few questions in a cyclical manner, growing progressively angrier at the lack of answers without ever really appreciating that there was no answer to be had.

We’ve all been there, and experienced the frustration of things going wrong—especially with Royal Mail. Seeing it from a third-party point of view, though, made me realise just how futile it is to try to complain at people who have nothing to do with the problem—even though it’s very easy to do.

To his credit, the man at the counter took it in good humour. It was entertainingly absurd, after all.

The nanny state on cycling

Whilst waiting for some friends at the Tube station, one of Transport for London’s numerous leaflets, entitled ‘Don’t let Winter disrupt your daily cycle’, caught my eye.

The gist of it is that cycle commuters should continue to do so, even in this especially inclement time of year—and by Jupiter’s beard, it’s cold this year. To encourage them, TfL give some helpful tips, ranging from the bleeding obvious to the patronisingly obvious:

Rain: On average, London’s commuters get wet just 12 times a year. Remember a fold-up jacket in your bag and look out for puddles.

What’s that? Puddles are wet? Avoiding them will help me to avoid getting wet? Thanks for that helpful information!

Headgear: A thin ski hat or balaclava worn under your helmet will keep your head warm.

A hat’s a good idea, but wearing a balaclava in the current political climate seems highly likely to get you shot. Seven times. In the head. At point blank range.

Cold: Cycling is great exercise so you’ll soon warm up, but take care of your fingers and toes with good gloves and socks.

Does anyone really need telling that gloves would solve their cold hands problem?

High Winds: Most bikes have enough gears to get up mountains, never mind upwind. Think positive: you’ll have the wind behind you on the way back.

How patronising. I suppose they’ll be telling us that London Underground’s perennially-broken escalators are good exercise next.

SuperWaba development on OS X Tiger

I decided to try some Palm OS programming. Although I have an entire book on the subject, the inconvenience of setting up a development environment has stymied me in the past. I’m not fan of Java—I despise its unecessary verboseness, its incomplete object orientation, and the ungainliness of Java applications on almost any platform—but SuperWaba, a miniature Java-compatible virtual machine aimed at handheld devices, seemed like it would do the trick.

I found a tutorial and downloaded the SuperWaba SDK

Installing the SDK was simply a matter of copying two files, SuperWaba.jar and SuperWabaTools.jar, and adding them to the Java classpath. It’s important to note that you must add the jar files themselves to the classpath; adding their parent directory won’t work.

Unfortunately, there are a couple of extra problems to address before you can actually compile and run even a simple Hello World application.

First, the version of Java used as standard in OS X—1.4.2—doesn’t work with Waba. But don’t panic! Version 1.3 is still available; you just have to find it. You can just type in the path to javac and java: they are found in ‘/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Commands’. But that’s rather too much effort. Instead, you can make a couple of symlinks. I have a ~/bin directory in my path; you can make the symlinks in /usr/local/bin if you prefer. I’ve elided some of the extravagantly long path, but you’ll have to type in the whole thing.

% ln -s (path)/1.3.1/Commands/java ~/bin/java13
% ln -s (path)/1.3.1/Commands/javac ~/bin/javac13

You can now use java13 and javac13 when compiling and executing Waba code.

The second wrinkle is that, even with the correct version, you still need to compile to the correct target: 1.1. The correct command line for compiling a Waba program is now:

% javac13 -target 1.1 Foo.java

Still a bit of a hassle, right? I thought, why not create a wabac to compile Waba programs? Here’s wabac (chmod it executable):

#!/bin/sh
javac13 -target 1.1 $*

To run the compiled program on the local machine for testing, use waba:

#!/bin/sh
java13 waba.applet.Applet $*

Finally, I made two more scripts in the same vein to give warp and exegen.

After having done all that, I was able to compile a SuperWaba Hello World program, run it on OS X, install it to my Palm (Tungsten T3) and run it there.

Once.

For some reason, my Palm wouldn’t run the same program ever again. Oh well, at least the development environment works.

Hope springs anew

Do you remember the end of the Star Wars trilogy, where the Dark Side is finally vanquished? Today feels a bit like that, albeit without the risible dancing teddy bears.

Darth Blair’s effort to introduce 90 days of internment—you know, the policy that worked so well in Northern Ireland—for suspected terrorists (which, one assumes, includes French technology journalists) was resoundingly defeated 322 to 291 in Parliament. (Being defeated by 31 votes is quite significant when his party’s majority is 67.) Have they been lacing the House of Commons’ tapwater with testosterone? There must be some explanation for this unprecedented epidemic of cojone-growing.

Not only is it nice to see Blair finally taken down a peg, it’s a damn good cause as well. Civil liberties have, at least in part, been defended against Blair’s ever-more-illiberal tendencies. Perhaps he’ll have the good grace to bugger off soon, before he manages to make even more of a mess of the world in general and the UK in particular.

You might, incidentally, recall Blair’s unconvincing protestations that his disastrous support of his master’s Iraqi misadventure was not responsible for increasing the terrorism risk in the UK. I expressed my opinion of this at the time, and therefore feel vindicated to see that no less than the former UK ambassador to the US holds the same opinion:

There is plenty of evidence around at the moment that home-grown terrorism was partly radicalised and fuelled by what is going on in Iraq. There is no way we can credibly get up and say it has nothing to do with it. Don’t tell me that being in Iraq has got nothing to do with it. Of course it does.

Vindicated. Not glad, though. I wish that we hadn’t needed to go through all this killing and maiming to get closer to the truth.

On the other side of the Atlantic, Blair’s master, George II, has also been seeing his kleptocracy assailed by the forces of light. On one hand, his lieutenants are under suspicion from the Fitzgerald investigation. On the other, his ratings with the American people are at an all-time low. To add to that, Republican fortunes are down in this week’s local polls.

I’m feeling positive about the world this evening.

Logo revolution

I was working on a new constructivist-influenced banner for this site, but it was lacking something. When I came across a scanned set of Chinese Cultural Revolution clip art, I knew what I had to do.

Inspired by a picture of a rifle-toting soldier, I got out my camera and posed as a laptop-wielding Hero of the Revolution. (The irony of holding a computer in a Cultural Revolution-inspired pose is not lost on me, by the way.) After a lot of tracing in Inkscape, I had a two-colour picture of myself in a suitably authoritative pose.

I’m sure that certain people are going to be pleased by the return of the red and orange colour scheme; I’m also glad to have it back myself.

If I’ve inadvertently broken something, please let me know.