james mckay dot net

because there are few things that are less logical than business logic

May 2007

25
May

Cycle helmets versus style and comfort

I sometimes wonder why I bother wearing a cycle helmet when I take my bike in to work. As far as I’m aware they’re not a legal requirement here in the UK and personally I think that’s a Good Thing. I’ve been observing other cyclists when I go into work and back home again, and it seems that we helmet-wearers are definitely in the minority. They do make you feel safer, but I sometimes wonder if that feeling is more a palliative than anything else. They’re uncomfortable, they make your head sweat like crazy, they’re bulky and cumbersome, and they make you look a complete wuss. And if what Wikipedia says on the subject is to be believed, there is no conclusive evidence that they make the slightest bit of difference to safety in the first place.

Regardless of whether I wear a cycle helmet or not, one thing you’ll never see me wearing when I’m on my bike is lycra — that horrible figure hugging stuff that reveals the outlines of those parts of you which should really be treated with more modesty. It may be aerodynamic and all the rest of it, but personally I think it makes you look so awful that it’s embarrassing, even if you are fit and healthy. It screams that you’re one of those fitness freaks who view cycling as an end in itself rather than as a means to an end and don’t care if you end up looking a total prat in the process.

22
May

The functional beauty of JavaScript

I’m the kind of developer who tends to sit on the “coding” side rather than the “design” side of the fence. I’m at my happiest when I’m designing web services, database access and application architecture, and although I do enjoy the odd creative spurt with Photoshop and the like, I don’t find it as interesting as the former. Consequently, until a couple of years or so ago, I only gave JavaScript and client-side development the bare minimum of attention that I needed to do my job. What with all the lunatic inconsistencies that you needed to handle in order to cope with Netscape 4 and Internet Explorer 4, I always perceived it as a monstrosity that needed a lot of ugly hacks to get it to do anything more compelling than bring up a dialog box saying “Hello world”, and was content to merely download whatever scripts I could find off the Internet to make it do whatever I needed it to do.

These days, of course, the story is quite different: you have some nifty tools such as Firebug, and despite the myriad rendering bugs in Internet Explorer, standards such as CSS and XHTML make browsers are a lot more compatible with each other than they used to be, plus of course there is all the cool stuff that you can do with Ajax. All this makes learning JavaScript a much more attractive prospect, and not surprisingly I’ve had to do a lot more of it in the past couple of years than ever before.

It’s been a real eye-opener. Far from being the ugly, kludge-ridden monstrosity that I’d always thought of it as being, JavaScript is actually a beautiful, well designed language with some very nice constructs. I always thought of it as one of those linear, procedural languages much like VBScript or Fortran with some vaguely object-oriented bits and pieces thrown in as an afterthought like PHP 4, but in actual fact it has much more in common with functional languages such as Scheme, OCaml or Haskell. It has closures and first-class functions, for example, which means that you can express some things in very clever, succinct and beautiful ways.

One particular JavaScript framework that has gotten my attention in the past few months is jQuery, and it’s become my library of choice for DHTML and Ajax gee-whiz. It’s an increasingly popular and fully featured toolkit that enables you to do some pretty clever stuff with only a handful of lines of code. For a simple example of what you can do with it, here is a code snippet that will highlight rows in a table when you mouse over it:

var highlightColour = "#ffff00";
var normalColour = "#ffffff";

$(document).ready(function() {
  $("#my-table tr").hover(
    function() {
      $(this).css("background-color", highlightColour);
    },
    function() {
      $(this).css("background-color", normalColour);
    }
  );
});

I love the simplicity of this. As the WordPress guys say, code is poetry.

(Update: Jeff Attwood has an interesting take on the subject where he describes JavaScript as “the lingua franca of the web” with the likes of Flash and Silverlight as merely pretenders to the throne.)

15
May

I am not as good at Trivial Pursuit as you think

I’ve been humbled. We played Trivial Pursuit at our church life group this evening. Guys versus gals. Everyone expected my team to win simply by virtue of the fact that I was on it, but unfortunately, we lost. :(

Contrary to popular belief, it turns out that I don’t know everything. Some people seem to think of me as a bit of a walking Wikipedia, and to be sure, maybe I have accumulated a bit too much useless information in my head from browsing said Wikipedia, but there is still a heck of a lot that I know absolutely nothing about. Such as celebrities, for instance.

The fact of the matter is that the latest version of Trivial Pursuit seems very celebrity oriented. I got the impression that the majority of the questions were about characters such as Britney Spears. Even some of the geeky questions were about Britney Spears. And I know nothing whatsoever about Britney Spears, other than that she’s a pop singer or something like that. I’ve never really followed the celebrity scene in any depth — I simply don’t tend to find it all that interesting.

I think this is probably why the ladies’ team won in the end though. Celebrities and the like tend to attract more interest from women. Cambridge psychologist Simon Baron-Cohen has published a book that goes into quite some detail about this kind of thing: he says that men’s brains are hard-wired for understanding and building systems, such as cars, computers and the offside rule in football, whereas women’s brains tend to focus more on empathising: subjects such as people, soap operas and Celebrity Big Brother. Make of that whatever you like (if you don’t like it, just put it down to the fact that he’s the cousin of the man behind Ali G and Borat) — I’m just making it my excuse for not sweeping the board with useless trivia about pop stars.