Blog » September, 2007

Texperts office party

 

A great man once wrote “There is nothing — absolutely nothing — simply half so much worth doing as simply messing about in boats”. Ok, so it wasn’t exactly a great Man, it was a great Rat (from ‘The Wind in the Willows’) but the sentiment was certainly correct. Never more so than when the Texperts descended on the river Cam from all corners of the UK for a spot of traditional punting. The first part of the evening allowed each of the Texperts to start putting names to faces as we leisurely drifted down-river under the guidance of the more experienced tillermen amongst us. All except my crew, who were subjected to half an hour of zig-zag steering and dodging overhanging trees before I got the hang of steering a punt properly…

Safe and (mostly) dry on solid ground, we moved on to The Granta pub to be fed and watered. Or in the case of some, fed, watered and then watered again! A banquet of sausages, burgers, breads and salads was enthusiastically vanished as Texperts from Aberdeen to Plymouth took the chance to get to socialise, many of them for the first time outside of the Online Office. Some others took the opportunity to fleece £6 from the quiz machine (how many people would immediately think of ‘Ochilview Park’ as the first Scottish Stadium to mind, other than a Texpert!).

From the pub we retreated back to Texpert Towers, which became the hottest, most Tex-clusive (sorry) club in Cambridge for one night only. With DJ RT and Masta G on the decks (or at least the itunes and speakers), Eden Street was pumpin’ on until the wee small hours of the morning. This was the perfect opportunity to talk some trivia, compare some notes and pop some shapes. Now, how long is it ’til Christmas…?

Pix to follow!

Hidden feature in Ruby’s Struct

 

Ruby LogoThe Ruby core library contains a nice little utility class called Struct, which provides a convenient way to bundle a number of attributes together, using accessor methods, without having to write an explicit class. So this:

class Customer
  attr_accessor :name
  attr_accessor :address
 
  def initialize(name, address)
    @name = name
    @address = address
  end
end

is (broadly) equivalent to this:

Customer = Struct.new(:name, :address)

Much nicer (and DRYer)!

But what if you want to define methods on the new class that you’ve just created? The Pickaxe Book says:

Ruby 1.9 and later allow you to pass a block to a Struct’s constructor. This block is evaluated in the context of the new struct’s class and hence allows you conveniently to add instance methods to the new struct.

Unfortunately most of us haven’t (yet) moved to Ruby 1.9, but there is good news! It turns out that this functionality has actually been present ever since 1.8.3 (here’s the relevant ChangeLog entry, although note that when it refers to [ruby-talk:02606], it should really refer to [ruby-core:02606]).

Imagine, for example, that we wanted to add a custom to_s method to our Customer class:

Customer = Struct.new(:name, :address) do
  def to_s
    "A customer called '#{name}' living at '#{address}'"
  end
end

Sweet!

Update (2007-09-05)

It turns out that there is another commonly used idiom which achieves much the same effect:

class Customer < Struct.new(:name, :address)
  def to_s
    "A customer called '#{name}' living at '#{address}'"
  end
end

However, it also turns out that both of these idioms may have problems when combined with Rails. For further information see this discussion on the ruby-talk mailing list.

Pictures from Unfest

 

Thomas and my whirlwind tour of the Edinburgh TV Unfestival 2007 drew demands for evidence from Texperts Towers. We have obliged. Here are some pix of our intrepid swanning at the various events:A glimpse of the geeks

At the Media Guardian Edinburgh International Television Festival session “Best of the Un-Festival: A glimpse of the geeks at the alternative TV Festival.” The audience get a glimpse of the back of my head! On the panel (from left to right): Suw Charman, Rosie Brown, Chris Jackson, Paul Cleghorn (Tape it off the Internet), Hannu Rajaniemi (ThinkTank Mathematics), and Ian Forrester (BBC Backstage).

Hannu Rajaniemi (ThinkTank Mathematics)

Hannu Rajaniemi of ThinkTank Mathematics presenting a session at the Unfestival on pervasive gaming and alternate reality gaming.

Saturday night party at The George.

The Media Guardian Edinburgh International Television Festival Saturday night party at The George.

“stealin ur audiencez”

“o hai tv execs, i am in ur internetz stealin ur audiencez”