30 May, 2005

Iraq

We've just had elections here in the UK, and the war in Iraq was brought up yet again. The frequency with which this long-suffering country is brought up by politicians and protesters-looking-for-something-to-protest has got beyond ridiculous.

In February 2003, Colin Powell presented the UN with a mass of clear evidence that Iraq was hiding something nasty from their weapons inspectors. Not even the French argued. Instead, they proposed sending more inspectors, and giving Saddam more time (presumably to finish whatever projects his scientists were hiding). No reason was suggested as to why the new inspectors would fare any better than the old ones. It was pure procrastination. France has never taken the lead in dealing with Iraq at the UN; they only throw spanners into others' attempts. The UN had already (twice) authorised the use of force in the event that their inspectors were not given free access to whatever information they wanted. So the US and its allies took the only logical route; they went to war and invaded Iraq.

The invasion was a success.
The invasion was the last success.
Things had actually started to go wrong before the invasion. Saddam killed thousands of his own people every month. The coalition forces would have had to have extremely bad luck if the war was going to kill less Iraqis than a few more months of Saddam's tyranny would. This humanitarian reason for going to war was an important message to that section of the population which was most opposed. Bush and Blair almost completely ignored it. As well as appealing to the more liberaly minded, this could have been a contingency plan in the event that weapons of mass destruction could not be found. There was every reason to assume that the invasion would create, after a short period of rebuilding, a much more pleasant Iraq. Unfortunately, certain people were so preoccupied with WMD that they ignored the humanitarian aspect.

After the invasion, things started to go wrong fast. The US/UK never revealed their post-war strategy, but we do know two things about it. One is that the powers-that-were (and still be) naively assumed that the Iraqi population, which had only ever know brutal dictatorships and sectarian fighting, would spontaneously settle down to a peaceful democracy. The other is that the State Department and Pentagon disagreed as to how the immediate occupational government should be formed. The Pentagon wanted to instate a government of Iraqis immediately. The State Department, which is so reliably wrong that it could be considered a belligerent foreign power, wanted to install an occupation government whilst waiting to see "who our friends are". "An Iraqi government to govern Iraq?" they must have mused. "Only that war-mongering Pentagon could think up something so absurd." Whenever the State Department says to do x, you can be certain that the correct course of action is -x. Bush foolishly listened to the State Department. Of course, the Iraqi population was delighted with the idea of being occupied by "The Great Satan", whilst it determined whom its "friends" were. The result was resentment, frustration, and an insurgency which blossomed into a bloody civil war.

So what actually happened to the weapons of mass destruction? One possibility is that Saddam Hussein was actually the victim of a scam by his weapons scientists. He was known to have had a liking for high-tech toys; they might have fabricated WMD projects for funding and misappropriated the budget. Another is that they were exported to Syria, a fellow Baath regime. The failure to find them, though, in no way detracts from the cause to go to war. Hindsight is 20/20; in February 2003, there was every reason to conclude that Saddam was preparing new CBN nasties to unleash on his neighbours and citizens.

05 May, 2005

.NET, Data Binding and Despair

You have a well-architectured application, i.e. one which uses an object persistence framework. You also want to modularise the GUI code; to this end, the controls to edit each object are wrapped in a UserControl. A control to edit a composite object is made by embedding the constituent user controls in a new user control, along with editors for any other persistent properties. Each UserControl exposes just one property, the bound object. How do you get data binding to work in such a scenario?

Have a look around the MSDN documentation. I'm not going to provide any links to it; I want you to get the "Microsoft experience" yourself. When you've finished, you'll probably need a valium. Unless you're binding a Dataset to regular controls on the same form, it isn't explained properly anywhere, although it will take a lot of wading through spotty and incoherent documentation to discover this. Hence you turn to Google. As you might never find a decent explanation (it took me long enough), I'll point you to one. Don't complain about the English; how good is your German? The most relevant page to the task at hand is this one.

OK, so you've written a dozen or so fooControl.DataBindings.Add("Value", persistentObject, "property"); lines to each control (so much for RAD and compile-time checks). Then you add a fooChanged event to each UserControl, and wire up the event handlers. Finally, you run the program. After tracing lots of mysterious errors to misspelled string literals in the Add(string, Object, string) methods, it might work. It probably won't though.

If you were foolish enough to go through with this frustrating exercise, you'll notice that I've skipped a lot of the steps in the linked page. This is to save you a lot of unnecessary trouble, because you can deduce from the failings in its current form that the missing code won't help. There is also a critical step missing; .NET data binding is so over-engineered, over-complicated and under-documented that it is simply not possible to make it work reliably with anything other than Datasets. I ended up writing the code to flag dirty objects and save or reload them as necessary myself. Don't despair though, we're in good company. If you look around the net you'll discover that (a)hardly anyone seems to be able to get this basic task right, and (b)whenever the question is raised at a Microsoft WebCast, the hosts avoid the question. I.e. Microsoft can't do it either.