Low Impact Management also applies to running technical projects. Micro-managing is a waste of time and energy, and drives developers to despair.

Introducing agile techniques such as pair programming and short iterations through example and opportunity, rather then by mandate and overbearing authority, ensures that developers feel comfortable picking up new techniques, and reduces the risk that they’ll feel pressure to perform.

Pressure is no bad thing, but as a manager you should ensure that your programmers work in a framework where a bit of pressure gains results, rather than simply increasing stress and fracturing the team. Developers tend to be the kind of people that perform well under stress, but they shouldn’t constantly be fighting agile build systems, or have new techniques forced upon them. Many agile consultancies see their ideas as the silver bullet that, once applied, makes any developer perform, and any project succeed.

Those of us that have read the book know better.

Ten years ago, OO using Java was the silver bullet. Before that, CORBA ensured a strong revenue stream for technical consultants. What we have to learn is that there isn’t one practice that works 100% for every team, and that we need the wisdom to pick and choose from the best of the bunch. That’s where agile consultants can earn their bread – through advice rather than proscription. It’s Low Impact Management.

I’m lucky enough to be learning German, though I’m afraid I’m not very good. When I was in high school I spent hours memorising verben, but now I’ve not got the aptitude or the patience. My tutor gets exasperated because I’ve learned some handy answers to all her questions in the lesson.

Mostly everything seems to take the dative, though I’ve little idea what that means. You can usually fluff gender – when spoken, mein sounds terribly similar to meine. Sometimes she catches me out, but not often.

Homework, however, I can do. German writing is an exercise in thinking like a compiler – for the most part the language is so uniform and regulated that you can solve most problems through a process of pattern matching and unification. Cui Bono, though.

If you’ve done any GUI programming at all, you’ll have come across a pattern like .NET’s System.ComponentModel.ISynchronizeInvoke. The problem it solves is fairly simple, yet only appears in a multi-threaded environment.

There’s one thread (it’s usually the first one created when the application starts, or at least the one that calls the entrypoint) that is responsible for creating and re-drawing UI controls. It handles messages from the Message Pump, and generally ensures that your UI looks as it should. It’s generally called theĀ GUI Thread.

You can see the actions of the UI thread in Visual Studio. Create a Windows Forms project, and have the eventhandler for a new button throw an Exception. Also, create an event handler for the UnhandledException event on System.AppDomain.CurrentDomain, containing the following code:

MessageBox.Show(((Exception)e.ExceptionObject).StackTrace);

Then just run the app and hit the button. You should see the GUI thread being created, along with a marshal from unmanaged to managed code for the button click. Anyway…

There’s a simple rule: you can only update the UI from the GUI thread. The reason for this is simply explained by example: imagine if you were able to add a list item from one thread, whilst you were moving the window, and the window was being re-drawn from another thread. You’d have half-drawn list items all over the screen, and no consistency in your UI.

The rule is simple, but not usually enforced for performance reasons. Luckily, since .NET 2.0, you’ll get a ThreadAccessException (or similar) when you do this when a debugger’s attached. Back in the bad old days of .NET 1/1.1 you’d sometimes get a Big Red Cross where a control should be. Sometimes you wouldn’t. It’d most often occur once you’d been through UAT and you application was in production.

So what’s the solution? You need to marshal to the GUI thread when you’re not on it, update the control, then get back sharpish. Luckily, System.Windows.Forms.Control implements ISynchronizeInvoke, which provides some stuff that’s interesting to us. This is the bit that most people will be familiar with, but for those that aren’t, here’s the summary:

  • bool InvokeRequired { get; } – Gets a value indicating whether the caller must call Invoke when calling an object that implements this interface.
  • Object Invoke(delegate method) – Synchronously executes the delegate on the thread that created this object and marshals the call to the creating thread.

Simply put:

protected void Update()
{
  if(this.InvokeRequired)
  {
    this.Invoke(new MethodInvoker(this.Update));
  }
  else
  {
    textbox1.Text = "foo"; //whatever
  }
}

Yes folks, that’s another nice bit of boilerplate code that you’ve got to put all over your GUI code. Not pretty. But it’s alright, really, because I don’t do that much GUI code – I’m an infreastructure developer. Just kidding – though I did once refer to GUI programming as ‘painting by numbers’, which didn’t go down at all well with some people at work.

Anyhow, long story short: I found this cool thing that lets you use C# 3’s lambdas to describe the work you want to do on the GUI thread.

It’s the Feast of the Epiphany today, so a little more poetry. Then that’s it for this year, promise.

This is the Journey of the Magi by T. S. Eliot. Eliot converted to Christianity in 1927 and published this poem three years later. It’s a description of that arduous journey from the point of view of one of the Magi; we don’t know which one. According to legend the wise men were astrologers and zoroastrians, which was the principle religion in the Levant before Mohamed arrived. Bathasar, Caspar and Melchior represent the three peoples of the world: Africa, Asia and Europe respectively.

“A cold coming we had of it,
Just the worst time of the year
For a journey, and such a long journey:
The was deep and the weather sharp,
The very dead of winter.”
And the camels galled, sore-footed, refractory,
Lying down in the melting snow.
There were times we regretted
The summer palaces on slopes, the terraces,
And the silken girls bringing sherbet.
Then the camel men cursing and grumbling
And running away, and wanting their liquor and women,
And the night-fires gong out, and the lack of shelters,
And the cities hostile and the towns unfriendly
And the villages dirty, and charging high prices.:
A hard time we had of it.
At the end we preferred to travel all night,
Sleeping in snatches,
With the voices singing in our ears, saying
That this was all folly.

Then at dawn we came down to a temperate valley,
Wet, below the snow line, smelling of vegetation;
With a running stream and a water-mill beating the darkness,
And three trees on the low sky,
And an old white horse galloped away in the meadow.
Then we came to a tavern with vine-leaves over the lintel,
Six hands at an open door dicing for pieces of silver,
And feet kicking the empty wine-skins.
But there was no information, and so we continued
And arrived at evening, not a moment too soon
Finding the place; it was (you may say) satisfactory.

All this was a long time ago, I remember,
And I would do it again, but set down
This set down
This: were we lead all that way for
Birth or Death? There was a Birth, certainly,
We had evidence and no doubt. I have seen birth and death,
But had thought they were different; this Birth was
Hard and bitter agony for us, like Death, our death.
We returned to our places, these Kingdoms,
But no longer at ease here, in the old dispensation,
With an alien people clutching their gods.
I should be glad of another death.

- T. S. Eliot

The bells of waiting Advent ring,
The Tortoise stove is lit again
And lamp-oil light across the night
Has caught the streaks of winter rain
In many a stained-glass window sheen
From Crimson Lake to Hookers Green.

Christmas is one of John Betjeman’s most openly religious poems, and one of my favourites. Published in A Few Late Chrysanthemums, in 1954, it combines a heart-warming Victorian Christmas ideal with a very reluctant religiosity.

It’s often said about Betjeman’s poetry that it allows people to identify with feelings they’ve never known or felt, like a kind of twee horoscope. More than that, I think he actively loved what we all like to think we love, too, and he had the skill and background to put it into words for us all to enjoy.

He inaugurated the Nooks and Corners column in Private Eye, which continues to this day. When I was in Manchester, a small row of houses in East Didsbury was torn down after being featured there, which was very sad. He campaigned vigorously against the post-war fetish of tearing down Victorian buildings, often using his popular status to succeed where others failed.

He contributed to the Shell travel guides, so I suppose he must have visited the North of England, but I don’t think he lived there at all. However, anyone born North of the Watford gap should smile at the first lines of the slightly macabre A Shropshire Lad. “The gas was on in the institute / The flare was up in the gym” – though who, born after 1950, say, knows what they mean?

He’s perhaps best known for his admonition of town planners: “Come friendly bombs and fall on Slough / It isn’t fit for humans now / There isn’t grass to graze a cow / Swarm over, death!”

Betjeman’s poetry is best read aloud: he has an innate understanding of cadence, and is often very funny. Try it!

The holly in the windy hedge
And round the Manor House the yew
Will soon be stripped to deck the ledge,
The altar, font and arch and pew,
So that the villagers can say
‘The church looks nice’ on Christmas Day.

Provincial Public Houses blaze,
Corporation tramcars clang,
On lighted tenements I gaze,
Where paper decorations hang,
And bunting in the red Town Hall
Says ‘Merry Christmas to you all’.

And London shops on Christmas Eve
Are strung with silver bells and flowers
As hurrying clerks the City leave
To pigeon-haunted classic towers,
And marbled clouds go scudding by
The many-steepled London sky.

And girls in slacks remember Dad,
And oafish louts remember Mum,
And sleepless children’s hearts are glad.
And Christmas-morning bells say ‘Come!’
Even to shining ones who dwell
Safe in the Dorchester Hotel.

And is it true,
This most tremendous tale of all,
Seen in a stained-glass window’s hue,
A Baby in an ox’s stall ?
The Maker of the stars and sea
Become a Child on earth for me ?

And is it true? For if it is,
No loving fingers tying strings
Around those tissued fripperies,
The sweet and silly Christmas things,
Bath salts and inexpensive scent
And hideous tie so kindly meant,

No love that in a family dwells,
No carolling in frosty air,
Nor all the steeple-shaking bells
Can with this single Truth compare -
That God was man in Palestine
And lives today in Bread and Wine.

-John Betjeman

Merry Christmas, and a happy New Year!

It’s silly season at work. There are two every year. In the summer, the place is quiet because the staff with children take the opportunity to go on two-week summer holidays. Nothing gets done, so you can plan ahead and get a stack of things ready to do then.

It’s a good time to work in isolation, not least because no emails you send or voicemail messages you leave are going to be answered for a while. Get used to finding things to do.

It was even worse when I worked for a large Anglo-Swedish pharmaceutical manufacturer. Sweden is heavily unionised, and the entire country effectively went on holiday for six weeks in the Summer. Completely ludicrous, but the third rail of management was trying to do something about it, so it went unspoken. Half the firm ground to a halt over the summer. The other half, of course, was in America, and they thought they were running the show.

Christmas is the other quiet time, when virtually everyone takes holiday. That seems really silly to me, becuase there’s quiet often nothing to do for those left in the office. Most people are there on production support, but their users are away drinking mulled wine at home. The others take long lunches and work short hours, which, to my mind, makes it a great time to be at my desk.

Whilst I’ve got all this time, I’m trying to learn New Things. I’m brushing up on my C++, and trying my hand (again) at Python. I bought the O’Reilly book years ago and never read it, and I’ve just installed the fantasic IronPython Studio, so now is a perfect time to give it another go.

Here’s a list of things to do:

  • Tidy up your project website.
  • Comment your public API.
  • Clean up your source control repository.
  • Arrange your stationary in reverse order of size.
  • Learn a new programming language
  • Learn the double-checked locking pattern
  • Learn about exception safety
  • Learn erlang.

It’s a common theme (at least in the UK) that people bemoan the passing of ‘institutions’ like Woolies, yet never went and bought anything when it was open.

We saw this over the last decade with small high-street shops going under whilst superstores and chain retailers survived, because they were able to use their colossal buying power to force suppliers to drop their prices.

Only recently have the public seen the error of their ways, and buying organic is now in vogue.

Woolworths was the first of the buy ‘em high, sell ‘em cheap retailers. The proprieter apparently had to put up signs to the effect that prices were fixed, and staff weren’t allowed to negotiate. Apparently customers were used to haggling over the price of their Fairy Liquid.

Similarly, since most goods were either 3d or 6d (thru’pence or sixpence, respectively), the registers (such as they were) were programmed to only accept multiples of 3d – if you wanted a penny chew, you either had to have three, or lose out on tu’pence.

It seems harsh, but businesses aren’t owed a market, and Woolworths lost its way a while back.

In C++, you can have a static variable defined in a function – scoped to the block, and with no linkage, but with a lifetime that extends from the first instantiation to the end of the program, unlike an auto. You’re not allowed this in C# – why not?

Well first of all, is it a good idea?

Static is one of the most overused and poorly understood keywords in the programming language ecosystem. In C++ alone it has at least five meanings – as a modifier affecting duration and linkage, orthogonally. It gets worse, because it was then co-opted to mean ‘determined at compile time rather than at runtime’.

In C++ static locals are commonly used as reference counters – initialise the counter once and increment it each time the function’s called. This can be replicated in C# by moving the static variable to class scope, but that feels like it breaks encapsulation.

Does it? No, it doesn’t. In OO, functions were never meant to contain data, only to expose and mutate it. A class or a struct is a container of data, so the class level is exactly the right place for your static.

Further, their use is actively dangerous, for reasons that aren’t immediately obvious. Functions with static locals are implemented with a hidden static boolean variable representing the initialisation state of the variable in question, as well as some simple code to check the state and instantiate it once. Predictably, this code itself isn’t thread safe. This issue is discussed at length in this codeguru article.

So, static locals aren’t really a very good idea in an OO environment, and also lull the unknowing developer into a false sense of security. Sounds like a bad candidate for a language feature to me!

Anders Hejlsberg didn’t take up my suggestions for new language features in C# 4.0, damn him. Instead we’re stuck with the moronic dynamic, a nod of the head towards stupidity and indolence.

The idea is that it’ll be easier to do some things which are currently fairly difficult, like interop with COM, and with dynamic languages like IronPython and IronRuby. In actual fact, the huge hidden cost is runtime initialisation of the whole DLR, which is not insignificant.

I quite admire the DLR, although (again) Microsoft have taken all the credit for clever techniques which are, in actual fact, quite old. Watch them do the same with HPC, MPI, and hosted applications (the cloud, whatever that means).

I won’t start a tirade about dynamic languages – they are what they are. But let’s not confuse ourselves: the words dynamic and huge runtime cost should be seared onto a developers’ mind next to each other. Any value whose type can’t be determined at compile time must, by definition, be determined at runtime. A compiler’s raison d’etre is to defer that cost – so beware, if you value productivity over speed of execution.

I still hold out hope for language support for ad-hoc tuples, although there are certainly strong arguments against their use. Members are anonymous, so they make a public APIĀ  confusing. There are constructs for structured data already – the clue’s in the name. The language is already big and convoluted, and there are other .NET languages that support them – C# shouldn’t be a panacea.

Get rid of var – that’d be the best thing. Or restrict its use so that lazy developers can’t use it to replace string or (why?!) int.