james mckay dot net

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

December 2007

17
Dec

Mrs Immery

I went to the dentist this afternoon.

She poked around my teeth briefly and said, “They’re looking pretty healthy. I’m quite impressed, given all the work I had to do on them initially,” then told me that one of my root fillings was chipped and needed to be repaired.

Not to worry, that was pretty quick and painless, and ten minutes later I was on my way back to the reception for The Extraction.

The Extraction, I hear you ask? Why do the receptionists do extractions when your teeth are healthy?

It’s actually the most painful bit of the lot. They may not extract anything from your mouth, but they certainly leave plenty gaps in your bank account. Forty-three pounds and sixty pence, to be precise. Ick. Seems dental fees have gone up a bit.

“Thank you, Mr Mac-EH,” said the receptionist, mis-pronouncing my name.

I don’t know why so many people insist on mis-pronouncing my surname. Listen up, folks, it’s pronounced Mac-EYE, not Mac-EH. Just think “iMac” with the syllables the wrong way round. If you’ve ever watched Porridge or Stargate Atlantis you should be well aware of the fact. Unfortunately, however, most people haven’t watched Porridge for years, and only geeks watch Stargate Atlantis, let alone know that it has a character in it with the same surname as yours trulyStargate Atlantis gets it wrong too. So, I think it’s forgivable.

I made eye contact. “Actually, it’s Mac-EYE. Everyone gets that wrong,” I said to her with a little laugh.

Getting the laugh right is important, as is the eye contact. You can’t take this kind of thing too seriously, after all. After all, she herself probably has a name whose pronunciation or spelling is even more ambiguous, as is the case for about half the names in the phone book. However, while I can generally get away with casually mentioning it to a dental receptionist, if I had been talking to a group of ten year olds, it would have been nothing short of cataclysmic. After all, one key rule of working with children is: if something makes you cringe, never let the little blighters know it.

I know this because once upon a time I was one such little blighter myself, as one Mrs F.M. Imrie found out.

When I was ten years old, one of our teachers, Mr P.F. Mann, broke his leg or something and ended up having to take half a term of sick leave. This was something of a disappointment, because “Puff Mann”, as we used to call him, was one of the most popular teachers in the school. He had a quirky sense of humour and a gift for making the dullest subjects come to life — talents that are absolutely essential for any school teacher.

The supply teacher who took his place was a stern, middle aged woman with horn rimmed glasses, her hair in a bun, a handbag with the initials “FMI” on the front, and less sense of humour than Darth Vader on a bad day. The first thing she did on walking into the room was to turn and write on the board.

“Im/rie.” With a large, distinctive, slash between the two syllables.

She turned back to face us. “Two syllables,” she said sternly. “Not three.”

Of course, this temptation is just too much for your average ten year old mind to bear, and right from the start, she was firmly entrenched in our minds as Mrs Immery.

Now every lesson at this particular school would start with the same ritual. The teacher would walk in. The class would stand up. “Good morning, boys,” the teacher would say. “Good morning, Sir/Mrs <insert name of teacher here>,” we would reply. The lesson would generally be preceded by five minutes or so waiting for the teacher to arrive. Ample time for one particular boy, in a bout of mischief, to turn to the kid behind him and say, “Immery. Pass it on.”

“Immery. Pass it on.”

“Immery. Pass it on.”

By the time the door opened, and Mrs Imrie walked in, the message had worked its way right round the class.

“Good morning, boys.”

“Good morning, Mrs Imm-ER-ry,” chimed out twenty-five pre-adolescent voices in unison, making the interstitial syllable as deliberate and obvious as possible.

Her reaction was most satisfying.

“I heard you practising in the library,” she said, with a look of total indignation. “Just how would you like it if I mis-pronounced all your names?” She then proceeded to read through the register, deliberately, systematically and sulkily mis-pronouncing all our names. When my turn came, she called me “McKite.”

Lame, I thought, struggling to keep a straight face. How are you supposed to take a teacher seriously when she gets as petulant as that?

However, there is a twist in the tale. You see, the mischievous boy who started this whole escapade that day was, in fact, me. And while there may not have been any immediate repercussions, a few years later we moved to the south of England, where 99% of the population are living with the delusion that “McKay” is pronounced “Mac-EH.” Some of them even persist in this misguided belief after I have pointed out their mistake to them. Mind you, the main offenders there are telemarketers, and I gather that telemarketers have scripts that they have to stick to, and they get fired if they deviate from them, e.g. by pronouncing your name correctly.

So perhaps I’ve been reaping what I sowed all those years ago. However, I’ve learned to just laugh it off. After all, perhaps one day I could end up having to work with ten year olds who read my blog.

Sorry, Mrs Immery.

17
Dec

Making the "zoom" slider on the Microsoft Natural 4000 keyboard do something useful

Unapologetic mindless link propagation time — this is just way too useful to let it slip: Olivier Dagenais on a hack to make the "zoom" slider on the Microsoft Natural 4000 keyboard function as a "scroll" slider. (Hat tip: Ayende).

14
Dec

How to list the sizes of the tables in a SQL Server database

Scott Mitchell gave some instructions on 4GuysFromRolla a while back on how to list the sizes of all the tables in a SQL Server database.

His solution uses a mixture of SQL and ASP.NET, but some people will want an alternative in pure SQL. So, with no further ado, here you go:

create procedure sp_get_table_usage
as
begin
    create table #t (
        name varchar(100),
        rows int,
        reserved varchar(100),
        data varchar(100),
        index_size varchar(100),
        unused varchar(100)
    )

    declare @name varchar(100)

    declare c cursor
        for select name from sysobjects where type='U'

    open c
    fetch next from c into @name
    while @@FETCH_STATUS = 0
    begin
        insert into #t
            exec sp_spaceused @name
        fetch next from c into @name
    end
    close c
    deallocate c
    update #t
        set reserved = rtrim(replace(reserved, 'KB', '')),
            data = rtrim(replace(data, 'KB', '')),
            index_size = rtrim(replace(index_size, 'KB', '')),
            unused = rtrim(replace(unused, 'KB', ''))

    alter table #t
        alter column reserved int
    alter table #t
        alter column data int
    alter table #t
        alter column index_size int
    alter table #t
        alter column unused int

    select * from #t
        order by name
end

You can change the sort order by changing the order by clause at the end. For instance, order by data desc will list them in descending order of size.

11
Dec

Volta, GWT and leaky abstractions

There’s been quite a bit of hype recently about Volta, the latest and greatest offering from Microsoft. It’s a bit like the Google Web Toolkit or RJS in Ruby on Rails, in that it allows you to write everything in C# and have it translated into JavaScript. You don’t even have to use C#—you could just as easily use VB, since it works on the compiled MSIL, converting that into JavaScript. It allows you to split your application at the lower tiers as well, automatically generating web services so that you can put, say, the user authentication part of your application on a different server to the main site.

It sounds like a good idea in theory, and no doubt it will attract quite a bit of attention from developers who do not want to have to learn yet another programming language. The main attraction of this kind of framework is for developers who are frightened off JavaScript by all the cross-browser insanities and the useless, bizarre and often totally misleading messages that Internet Explorer throws up when it encounters a JavaScript error. The old “Syntax error in line 0″ syndrome. There is also the issue of testing on multiple browsers on multiple operating systems. But hey, now we can write JavaScript without writing JavaScript!

But is it really necessary?

About a year ago, I would have given an emphatic “yes” in answer to that question. However, a lot has happened in the JavaScript world in the past year and a half. We now have free virtualisation software and Intel Macs, so you can run several different operating systems—Windows XP, Windows Vista, Windows Server 2003, Linux and Mac OS X—on the same machine if you are that way inclined, making cross browser testing a whole lot easier. Firebug turns Firefox from a humble browser into a powerful debugging tool. JavaScript frameworks such as Prototype, Scriptaculous, jQuery and Dojo abstract away all the nasty cross-browser stuff, allowing you to discover just how nice a language JavaScript really is. And on top of that, they give you transitions, drag and drop, thickboxes, fade anything techniques, and a whole lot of other eye candy and cool stuff as a bonus.

I’m also rather sceptical of the whole write-language-A-in-language-B business.

Admittedly, I’ve never actually tried the Google Web Toolkit or RJS, but my guess is that while there’s undoubtedly a lot that you can do with them, I doubt if they’re the most efficient. Writing JavaScript in C# or Java or Ruby will inevitably involve a layer of abstraction, and all abstractions are, to a greater or lesser extent, leaky.

Now before you shout me down on this one, yes, I know that Prototype and jQuery are abstraction layers, and therefore may well have plenty leaks of their own. However, the point that I am making is that the process of converting between languages adds a whole further abstraction layer in addition. Making the whole thing even leakier.

At present, Volta has a lot of leaks. Late binding is not supported, for instance, which means that languages such as IronPython, IronRuby or PHP (via Phalanger) are effectively ruled out, and Visual Basic requires you to use Option Strict. This seems a bit surreal given that JavaScript itself is also a dynamically typed language, but it is a consequence of the fact that it all goes through the statically typed MSIL intermediary, and support for reflection (which is needed to simulate dynamic typing on a statically typed platform) is severely limited.

I am also sceptical of the benefit of being able to move parts of your application between the client and the server. Far from making things simpler, this could introduce a whole new can of worms if it is not carefully thought out, partly in terms of performance, particularly if you end up with a very chatty interface between them, but much more seriously, in terms of security. Maintaining state across multiple tiers is also very difficult if not impossible to abstract completely transparently, and it will be interesting to see how they tackle this problem.

However, it is probably a little unfair to knock it too much at this stage. Volta is only a technology preview and pretty experimental, so obviously some of these leaks will be patched as it matures. On the other hand, undoubtedly other leaks will remain and may even prove impossible to patch—in particular, performance will never be the same as with pure vanilla JavaScript, and download sizes will still be greater. So by all means check it out if you like, but as far as I’m concerned, if a task calls for JavaScript, JavaScript is what I intend to use.

01
Dec

Britain's best motorway service station

For anyone on the road heading to (or from) Scotland, Tebay services (Westmorland Farm Shops) on the M6 is the place to stop. It’s Britain’s only privately owned motorway service station and you really notice a difference. The food is way nicer for starters, and it has a much more homely atmosphere than the enterprisey corporate blandness of all the other places.

I’m writing this post from the above establishment, where we’ve stopped off for a meal en route to Scotland for a week’s holiday. We’ll be getting some much needed rest as well as celebrating my granny’s birthday on Tuesday. She will be 91.