Blog Posts

And if there were, what then?

The Alpha Course people have been running a bunch of poster ads built around the slogan “If God did exist, what would you ask?”. The posters are filled with anodyne questions like “What’s the point?” or “Is this it?”. They also tend to have large amounts of white space on them - I’m sure there are enterprising graffiti artists out there who look upon that as a fine opportunity. So, here’s a few questions I’d ask god, if it existed:

Arguments you wouldn't make in Alabama

I spent the weekend at the UK Sacred Harp Convention, singing blood curdling hymns to the glory of god, very loudly with a hundred or so others. Great fun so it was. There’s something joyous about hollering out a hymn that opens with the line “And am I born to die?” and ends with the stanza Waked by the trumpet’s sound I from my grave shall rise And see the Judge in glory crowned And see the flaming skies

If you're going to add a hook, make it a big one

Jay Fields responds to on Ola Bini’s Evil Hook Methods? about the common ruby idiom that lets us write: class Fruit include DataMapper::Resource property :id, Integer, :serial => true property :name, String property :notes, Text, :lazy => false end What Ola and Jay don’t like about that is the way that a single include DataMapper::Resource actually adds class methods to Fruit because the implementation of DataMapper::Resource.included looks like: module DataMapper::Resource def included(module) module.

Oh. Bugger

If you asked me to name my favourite radio and TV comedy, the odds are very good that Geoffrey Perkins had a hand in most of them. When I found his obituary in this morning’s Guardian I felt almost physically winded. I never met him, I don’t know anyone who did, but he was someone who helped to make the world a pleasanter place to be in. My thoughts are with his family and friends, who are no doubt even more gutted than I am.

Get sophisticated

Ruby’s primitives (Strings, Hashes, Arrays, Numbers - anything that has a literal syntax) are fine things. But that doesn’t mean you should use them everywhere. You’re often much better off wrapping them up in your own Value Objects. Something I was working on at Railscamp this weekend threw up a great example of why it makes sense to replace primitives with more specific objects as soon as possible. Tom Morris asked me to take a look at Rena, an RDF/Semantic Web thingy.

Work with us

If the last post about our Javascript issues didn’t put you off, then you might be interested to know that we’re hiring. If you’re an experienced, test infected Ruby on Rails programmer with some Javascript and a real world consumer website or two under your belt, and you’re happy to work in Newcastle upon Tyne, then we definitely want to hear from you. I’d probably be interested in at least hearing from you if you’re an experienced dynamic language programmer who has only recently made (or is considering making) the switch to Ruby and Rails.

Usability testing (throws) rocks

Usability testing is wonderful. But wow, its humiliating. I’ve spent the last few weeks working on the Amazingtunes in page player. Amazingtunes is a music site, so we need to play music. However, we don’t like the way that most music sites work; either the music stops as you go from one page to another, or the player is a huge Flash app running in its own window. There has to be a better way.

Announcing Announcements for Ruby

I’ve just pushed a just about usable (but horribly untested) port of Vassili Bykov’s very lovely Smalltalk Announcements framework onto github. It’s a very raw port at the moment (the interface isn’t what you’d call idiomatic ruby yet), but I shall be working on that soon. Documentation (beyond a synopsis in the readme file) is nonexistent, but I reckon that there’s the core of something useful there (I’ve got plans for using it in Typo as the basis of a Wordpressesque plugin architecture and I need it for my Sooper Sekrit Project too…).

git is the monads

When, in the course of learning about Haskell, I reached the point where I thought I understood what Monads were for, I wrote about it. In the comments, Seth Gordon observed that: There are two kinds of people who try to learn Haskell: the people who give up because they can’t figure out monads, and the people who go on to write tutorials on how to understand monads. I remembered this today as yet another git tutorial rolled by in my newsreader.

Rails tip: Dealing with out of sync migrations

Sometimes, for one embarrassing reason or another (usually involving chaotic branch merges…) a database migration can get leapfrogged. When this happens, it’s tempting to renumber the leapfrogged migration, but that breaks any servers where the migration didn’t get renumbered. Here’s how I dealt with it recently: class MaybeOldMigration < ActiveRecord::Migration def self.up unless old_migration_applied? OldMigration.up end end def old_migration_applied? # Checks that the schema looks as it should # if the old migration got applied end end Yeah, it’s a hack, but it’s a fairly robust hack.

A quick Javascript formatting tip

IE’s a pain. The particular pain I want to write about is its pickiness about Javascript object literals. Consider the following Javascript object: { success: function () {…}, failure: function () {…}, } If you’re used to programming in Perl or Ruby, that trailing comma’s perfectly fine, in fact leaving it there is sometimes considered good practice because it makes it easy to extend the hash, just add a new row and leave another trailing comma.

Ads are gone

Back when I was writing the occasional “How do you find me?” article, I would get some weird ads showing up. On one occasion, I commented that the searcher had obviously just typed a homework question into google and expected an answer. All the ads on that page ended up being for sites that would write your essays for you. “Hmm…” I thought, “That’s not good.”, and set about adding those advertisers to the block list.

Fat is an economic issue

Terry Pratchett once observed that a character of his was anorexic because every time they looked in a mirror, they saw a fat person. By that measure, I’m anorexic, though I tend to avoid mirrors. By more objective measures, I’m morbidly obese - 6' tall, 346 pounds; the Body Mass Index calculation is never going to give a good number. To listen to some sections of the press, I might as well be public enemy number one.

Code is data, and it always has been

I’m just back from the first Scotland on Rails conference, and a jolly fine conference it was too. Much kudos is due to Alan, Graeme, Abdel and Paul. It was hard to believe that this was the first conference these guys have run and I think all my fellow delegates hope it won’t be the last. As I said in the Pub on Saturday night, I’d had a talk proposal knocked back and, in that situation, it’s terribly easy to find yourself sitting in a session thinking “Bloody hell, my talk would have been better than this!

Tragedy

There’s always a moment, in a perfect tragedy, where you dare to hope that maybe the heroes are going to break the surface tension of the plot and escape. That perfect moment in Romeo and Juliet where, no matter how often you’ve seen it, you hope that this time, Juliet’s message will reach Romeo. Or, when watching Cruel Intentions, you find yourself hoping that the writers have managed to wangle a happy ending.

Javascript scoping makes my head hurt

Who came up with the javascript scoping rules? What were they smoking. Here’s some Noddy Perl that demonstrates what I’m on about: my @subs; for my $i (0..4) { push @subs, sub { $i } } print $subs[0]->(); # => 0; Here’s the equivalent (or what I thought should be the equivalent) in Javscript: var subs = []; for (var i in [0,1,2,3,4]) { subs[i] = function () { return i; } } alert subs0 // => 4 What’s going on?

Baby's first screencast

If you follow the Ruby blogs, you will probably have seen a bunch of programmers attempting to do something akin to Haskell’s maybe, or the ObjectiveC style, message eating null. Generally, by about the 3rd time you’ve written if foo.nil? ? nil : foo.bar … end you’re getting pretty tired of it. Especially when foo is a variable you’ve had to introduce solely to hold a value while you check that it’s not nil.

I am not a rock star

I am not a rock star. I am a computer programmer. I think I’m quite a good one. You are not a rock star either. 387,000 matches to that query. Can we all just… I don’t know… grow up please? Mutter… grumble… chunter… I’m 40 you know! Updates I have it on reliable authority that James O’Kelly is a Ruby on Rails Rockstar that would make a great addition to any team!

Joined up thinking: why your resources want links

Remember the good old days? The days before Google? The days before Altavista? The days when a 14k4bps modem was fast? Did I say good old days? In those days, the web had to be discoverable ‘cos it sure as hell wasn’t searchable. The big, big enabling technology of the web was the humble Go somewhere else. Placing the links right there in the body of the document turned out to be exactly the right thing to do.

Patterns and principles

Recently I’ve been thinking about the way that patterns on different scales interact with each other. If you read Christopher Alexander’s A Pattern Language, the first pattern in the book is Independent Regions, which are talked about within the context of a World Government, so it seems like a huge pattern. And it is, sort of, but it’s scale invariant - it applies at the level of countries, but it also applies to states, cities, neighbourhoods, streets, houses and arguably even rooms within those houses.

The authentication tarpit

At work, we’re looking at adding the Atom Publishing Protocol in a few places where it makes sense. APP’s got a lot going for it - the spec is a great example of how to design a Resourceful API and is worth reading even if it’s not an immediately good fit for your application. But… It’s one of the givens of good application security that you don’t store passwords in clear text and you do your level best not to send them over the wire in cleartext.

Martin Fowler's big mouthful

Martin Fowler is writing a book about Domain Specific Languages and, because you could never accuse Martin of a lack of ambition, he’s trying to write it in a reasonably (implementation) language agnostic fashion. It’s fairly easy to write an implementation language agnostic book about old school DSLs, what used to be called little languages - there’s a fairly well established literature and theory to do with lexing, parsing and interpreting.

Getting to grips with Javascript

I’ve been busily adding AJAX features to the work website, and I got bored of writing Form handlers. I got especially bored of attaching similar form handlers to lots of different forms on a page, so I came up with something I could attach to document.body and then plug in handlers for different form types as I wrote them. So, I wrote FormSender and set up my event handler like so:

The secret of comedy is...

… timing. You either have it or you don’t. Does this count as good timing? Finish up some improvements to the way Typo sweeps cached pages Announce Typo 5.0 Go down with a horrible cough and cold that leaves you exhausted and incapable of hacking Discover that the ‘improvements’ in Typo’s cache sweeping can, occasionally, cause it to wipe the entire Typo installation directory Stagger out of bed. Attempt to fix problem Release Typo 5.

Typo 5 is out - and more on the future

Right, we’ve cut a Typo 5 gem and it’s on rubyforge and heading to various mirrors I hope. Frédèric’s writing the release notification which will be appearing on Typosphere Real Soon Now. It’s been a surprisingly tricky process - we’re now requiring Rails 2.0.2 because the workings of view_paths have changed in a way which means we can’t quite make themes with Rails 2.0 and 2.0.2 and working with the edge seems like the more sensible proposition.

Rails 2.0 and the Future of Typo

So, if you’ve been watching the Typo tree, you’ll see there’s been a fair amount of activity on it since Rails 2.0 got released. There’s a new default theme replacing the rather creaky ‘azure’, and a fair amount of work on getting our code compatible with the current state of Rails. As we work on this, it becomes apparent that Typo’s code is getting horribly brittle. I have said before that there’s been several places where we’ve zigged before Rails zagged, and we’re paying the price for that.

Comprehensible sorting in Ruby

Here’s a problem I first came across when I was about 13 and helping do the stock check at the family firm. The parts department kept all their various spare parts racks of parts bins. Each bin was ‘numbered’ with an alphanumeric id. We had printouts of all the bin numbers along with their expected contents and we’d go along the racks counting the bins' contents and checking them off against the print out.

Can I get a witness?

Worrying about test coverage when you’re doing Test- or Behaviour-driven development is like worrying about the price of fish in Zimbabwe when you’re flying a kite. Your tests are there to help you discover your interface and to provide you with an ongoing stream of small bugs to fix. If you write them cleanly, and keep them well factored (you are refactoring your tests, aren’t you?) they will help to document your intent too.

An announcement

Do you have a PC, Xbox 360 or anything else that will run the Valve Orange Box? If so, get hold of a copy and fire up the Portal subgame. That is all.

Things that make a developer cry

So, we’re doing a cobranding exercise at work. The idea being we serve up a branded version of amazing tunes in a subdomain of our partner, their users get a skinned version of the site that feels like part of the partner’s site, we get an influx of new users and everybody is happy. One aspect of this is we’re using the partner’s site to handle authentication. Today, we got all our ducks in a row and started authenticating against the partner’s SOAP service as part of our user testing.

Leopard Polish

Yes, I’ve upgraded to Leopard. Yes, it’s spiffy. The headline features like Time Machine are great, but I’m loving the little details more. For instance, the first time you go to run an application that’s been downloaded from the net, a dialogue pops up reminding you that the file has been downloaded and asking if you want to trust it. It’s a nice bit of security, and it asks you the question at the right time.

Time flies when you're enjoying yourself

It’s been a while since I wrote anything here, mostly because I’ve been indecently busy. Well, up until last Sunday when I managed to trip over a low wall in our garden and, in the process take off a large amount of the skin on my left shin. A mere flesh wound, but painful, embarrassing and it’s left me sporting what looks like a foot long, white, elastoplast. The worrying bit is that, when I went to get my wounds dressed, the nurse took one look at my bulk and demanded a urine sample.

Rails tip: Side effect filters

Some bugs are easy to overlook. One that has a habit of catching me out is a Rails filter that returns false occasionally when it’s being evaluated purely for its side effects. Here’s how I’ve started working round the issue: def side_effect_filter return if some_conditions_not_met? … ensure return true end What happens here is that the ensure catches any return and returns true instead. The catch is that if something throws an uncaught exception anywhere, it too gets caught by the ensure and true is returned.

Typo on Rails 2

Whee! Sat in my home directory is a version of typo that appears to work with Rails 2.0. I ended up giving up on the themer approach which proved to be very hard to get up and running transparently - things kept disappearing off around infinite loops, which is no fun at all, let me tell you. So, ended up cheating and ended up monkeying with @@view_paths directly, which is almost certainly against the rules, but has the cardinal virtue of working.

Railsconf Europe Photos

<typo:flickr img=“1455226602” size=“medium” caption=“James Duncan Davidson” /> I’ve finally started uploading the scans from RailsConf Europe last week. There’s still one more roll to scan and another 9 shots in the camera, but I’m pretty pleased with the results so far. I didn’t really start shooting until about halfway through the last day. The light in the hotel was horrible and I just wasn’t in the mood, then suddenly I’d shot three rolls and was wondering where I could find another roll of Neopan 1600 at 9pm in Berlin.

Today's Noun is: Reticence

What does the OED say reticence is? Reticence: Maintenance of silence; avoidance of saying too much or of speaking freely; disposition to say little. Pretty straightforward. When I chose reticence as one of my five nouns for programmers it was another reminder that objects are not the same as datastructures. Well designed objects keep their cards (instance variables) close to their chest. Client code tells objects what to do, it doesn’t ask them to kiss and tell.

Slide Of The Conference

Britt Selvitelle of Twitter gave a cracking talk at RailsConf Europe about scaling Rails applications to Twitter scale. It was great. Full of advice that we shall definitely be taking on board as we continue to develop amazing tunes. However, the last slide before the inevitable “Any Questions?” was the slide of the conference. It read: It’s 2007. Every spammer has your email address. Put it on your goddamn webpage so people can get ahold of you about interesting things

My head hurts

During DHH’s keynote at RailsConf Europe it was apparent that there’s a great deal to like in edge rails, so I thought I’d have a crack at getting Typo up on it. Ow. I’d expected the pain points to be related to routing, but it seems that the rails routing system is approaching the level of the Excel calculation engine - nobody dares touch it for fear of breaking things, so typo’s custom routes seemed to work quite happily.