| Main |

November 30, 2007

IT is not about Control and Security

From MacWorld:

“The use of unsanctioned devices, iPhone or otherwise, in the enterprise adds tremendous complexity for IT managers and executives trying to develop strategies around mobility while maintaining control and security over such devices,” wrote IDC Mobility Enterprise Device Solutions analyst Sean Ryan, in a press release. “IT managers need to be aware of the implications of allowing iPhone access to corporate networks.”

It’s a shame that many in the IT industry have forgotten what IT is fundamentally about. It is not about “maintaining control and security” as the analyst above suggests. It is about improving the productivity of a business through the use of computer technology to automate common tasks and to assist in the running of the business.

Certainly there needs to be some element of thought given to security, but it needs to be balanced with an understanding that the IT department is there to serve the needs of the business and its staff.

“Islam is a moderate religion”

“Islam is a moderate religion… if a person deserts Islam, we kill him.”1

Those were the words spoken by a Muslim cleric in charge of a “re-education facility” (the Centre for Prevention of Vice and Promotion of Virtue) in Afghanistan during the bad old days of the Taliban. This was the place you were sent if, as a man, you shaved your beard. Or if you repeatedly failed to turn up for prayer (and survived the beatings that would be dished out by the Taliban patrolling the streets). Or were caught listening to music, especially “music with women singing”. Or playing games. Or for committing any number of other offences, many of which would seem trivial to you and me.

Why does this quote seem appropriate now? Well, apparently Gillian Gibbons deserves to be shot for “insulting religion”. How did she commit this grievous crime? By asking her class to name a teddy bear; they chose the name “Muhammad”.

I happen to think that she was rather naïve to allow the name “Muhammad” to stand, but I certainly don’t think she deserves to be shot for it. Whether she deserves the 15 day jail sentence or the order expelling her from Sudan is a slightly more difficult question though; liberal commentators claim that this is wholly unacceptable, but then those self-same liberals also claim that it is the right of the religious to follow their religion, and you can’t really have it both ways2. At least, not unless all religions adopt liberal principles as their fundamental ideals, and they simply don’t.

1 This quote is from Sean Langan’s excellent Behind the Lines programme which was shown on BBC2 in 2001. The wording is from memory, but I’m fairly sure it’s accurate. If anyone has a copy of the programme and can check, I’d be very grateful for any corrections.

2 I should be clear: personally, I think Gillian Gibbons’ treatment and the reaction of some of the Sudanese people is wrong. But you have to acknowledge that Sudan is a religious state, and that the law allows for religious punishment. As an atheist, I think that is wrong, and I don’t believe that the religious should have a fundamental right to hold irrational beliefs, or indeed to act on them (especially in mock offence). But as a realist I would not go to a Muslim country and then do anything likely to inflame religious sensibilities. And if I were to do such a thing, I would expect to be treated harshly, because that is the current mood of the Islamic world.

November 20, 2007

Well done H.M. Revenue & Customs

It seems that our glorious government (yeah, I know, the sarcasm will drip on the carpet…) has outdone itself once again. Having admitted twice already in recent days that it had “misplaced” the details of millions of British taxpayers, it has just had to admit to having lost the child benefit and bank details of, get this, 25 million people.

Yes, you read that right. Nearly half the population of our country has just been told that a CD containing (apparently) unencrypted copies of their personal data has been lost in the mail.

Why didn’t HMRC encrypt the data on the CDs? Why didn’t they send the data by encrypted e-mail? Or upload it to a secure server? Why did the National Audit Office not simply have access to the HMRC computer system?

Who knows?

(I’ll just add that I don’t think it’s fair on the basis of this almighty cock-up to criticise the idea of identity cards. If we’d had identity cards and a proper centralised database, there wouldn’t have been any need to send the data on blasted CDs in the first place. But it does show that whoever is in charge of the whole identity card and government database project needs to know what they’re about. i.e. Let’s not use the same people responsible for this debacle. Or the people the banks used to design their Chip & PIN system, which it turns out is not nearly as secure as it could have been.)

e-books are pointless

John Gruber just wrote a piece about how he hopes that Amazon’s new e-books flop.

Personally I don’t think we need to hope. The physical experience of a real book is still far superior to any electronic version I’ve yet seen. The only way I’m ever going to be persuaded that e-books are a good thing is if someone makes a physical e-book that looks and feels like a real book, that has multiple electronic pages (preferably at least twenty) and onto which I can load any of my digital books.

Even then e-books will be worse than real books, because publishers will be concerned (and rightly… as a software developer, I’m only too aware of the horrible problem of copyright infringement and the total lack of respect the public has for other peoples’ hard work) about theft of their material. That isn’t a problem with real books, since it’s uneconomic (generally speaking) to copy one.

In the meantime, I may use the on-line version of Version Control with Subversion, but I still own (and use) a paper copy, which says it all, I think. The only books I use entirely in on-line form are Apple’s developer docs, and the only reason for that is that they’re updated so regularly and are so large that printing them is uneconomic.

Global Warming

Stephen Fry on Global Warming and the differences in attitude between the Britain and the United States:

For another difference we have to face between our cultures is that the average position on global warming in Britain seems to be: ‘It exists, we humans are causing it, we’d better do something about it’, whereas the average position in America might be interpreted as, ‘I’m not convinced and anyway America certainly shouldn’t sign up to do anything about it if China doesn’t.’

It occurs to me that it is almost supremely ironic that a nation like Britain, whose total annual CO2 output is a tiny fraction of global emissions, should consist largely of people who have been fooled into thinking that anything they do could affect climate change, while the United States, which is by all accounts responsible for around 25% of all CO2 emissions and whose citizens might conceivably make a difference if they changed their behaviour, seems largely composed of sceptics. Here in the U.K., our influence on the problem is overstated by the environmental lobby to a frankly ludicrous degree, and often in a fairly underhand manner (For instance, you are more likely to see a graph of CO2 output by country per capita than as a percentage… why? Because it puts the U.K. near the top of the scale rather than near the bottom where it belongs. Perhaps U.S. citizens are better educated and therefore would not fall for that kind of cynical ruse?)

I am slightly sceptical myself, in as much as it is without a doubt much easier to obtain funding for research that supports the man-made climate change conclusion than research that goes against it. And whether or not the conclusion is true, this funding distortion will certainly contribute to some exaggeration.

It is also the case that the world has been a lot warmer at some points in the past, so I often think that the doom-sayers would do well to qualify their remarks by explaining that the primary catastrophe that they are concerned about is the effect on human civilisation and they might also consider stating openly the fact that the Earth’s climate may well have warmed up anyway, just not as fast.

And don’t get me started on the precautionary principle; I don’t find that old chestnut in the least bit persuasive. Why? Because I can use it to justify anything. Well, almost anything.

Let me give an example: there is a risk (only a very tiny risk, but a risk nonetheless) that walking through the streets of Fareham I might encounter a hungry lion. Say it’s escaped from a nearby zoo. Now everyone knows that hungry lions are not the best thing for a human being to bump into. In fact, the consequences of such an encounter would likely be pretty dire (bluntly: I’d most likely die). So, invoking the good old “precautionary principle”, it is now essential that I carry on my person equipment to defend myself against hungry lions. The argument is ridiculous, of course, but it’s the same as most other uses of the precautionary principle; the flaw is that it does not take into account a proper assessment of the risk of the event in question, often because the person invoking the principle has no idea of the magnitude of the risk, though they may appreciate that a particular event may have rather dire consequences if it does in fact happen. You can substitute for the hungry lion any manner of other things. Getting cancer from E/M radiation from mobile phones (or WiFi). The possibility of life on Earth being extinguished by a gamma ray burst. The risk that the sky will, in fact, fall on our heads. The list is endless.

So, do I think we should continue to churn out CO2? You may get the impression from the above that I do. You would be wrong. I think we should move to nuclear power generation as soon as possible. And I think we should spend vastly more money on the international fusion project, at the same time bringing the timetable forward by at least a few decades. But should we panic and enact the kind of legislation that would make every New Luddite proud? No, I don’t think so.

On this the U.S. view is quite right. The way to avoid global warming is innovation. Many of the tools we need are already at our disposal or are actively being worked on. Rather than supporting unsustainable and silly ventures like on-shore wind power, or downright dangerous propositions like biofuels (which still produce CO2 and have the additional downside of markedly distorting the agriculture market to the extent that we now have a wheat shortage), we would better spending our resources furthering research that will end the problem for good.

November 19, 2007

Commands and Mouse event handling in Cocoa

In the Cocoa Event-Handling Guide, it talks about two methods of handling mouse drags, namely with a tracking-loop and what it refers to as the “three-method approach”.

The two have some obvious pros and cons, so sometimes Cocoa programmers use one method and sometimes the other, even in the same program.

Usually you can write your code either way and it will pretty much work. However there are a couple of nasties that I ran into today that I couldn’t find any information on anywhere. Maybe there’re obvious to some of the people who’ve been writing Cocoa programs since before it was even called Cocoa, but they weren’t to me and it wasn’t especially obvious that there was a good way to work around them.

What are these problems? Well, consider this… your application is tracking the mouse because the user is manipulating some object in your document. Now, your user is feeling mean, and during tracking hits ⌘X, Cut (if that one works in your app, try hitting ⌘Z, Undo, instead).

I’m guessing that a substantial number of apps just fell over. Or at least behaved in a less than ideal way. And even those that didn’t might well find that their behaviour is inconsistent because some parts of their app use a tracking-loop and others use the three-method approach.

So, let’s explain what happens:

Case 1: The Modal Tracking Loop

This is often the easiest way to implement mouse tracking code. It also happens to have slightly better performance in many cases, particularly on slower machines. As a result, it’s quite widespread, even within the Cocoa frameworks themselves.

Most probably the code you have is using some variation on what’s written in the documentation, i.e. something like this:

- (void)mouseDown:(NSEvent *)theEvent {
  NSPoint pos;

  while ((theEvent = [[self window] nextEventMatchingMask:
    NSLeftMouseUpMask | NSLeftMouseDraggedMask])) {

    NSPoint pos = [self convertPoint:[theEvent locationInWindow]
                            fromView:nil];

    if ([theEvent type] == NSLeftMouseUp)
      break;

    // Do some other processing...
  }
}

If you do this, what you’ll find is that your application runs all the commands corresponding to the mnemonics the user pressed after he or she lets go of the mouse button. Quite what your user intended to do isn’t clear, but there’s a good chance it wasn’t that, particularly if they’ve hit e.g. ⌘Z more than once during the tracking loop.

Fortunately, the solution here is rather simple; all you need to do is discard any keypresses you don’t want to handle. The necessary changes are highlighted in italics:

- (void)mouseDown:(NSEvent *)theEvent {
  NSPoint pos;

  while ((theEvent = [[self window] nextEventMatchingMask:
    NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSKeyDownMask])) {

    NSPoint pos = [self convertPoint:[theEvent locationInWindow]
                            fromView:nil];

    if ([theEvent type] == NSLeftMouseUp)
      break;
    else if ([theEvent type] == NSKeyDown) {
      NSBeep ();
      continue;
    }

    // Do some other processing...
  }
}

Depending on your application, you may also want to discard NSKeyUp events, though you probably don’t want to beep for those.

Case 2: The Three-Method Approach

Let’s start by explaining what happens. If you use the three-method tracking approach, keyboard events are processed as normal during tracking. And that means that NSApplication will look up mnemonics and dispatch the appropriate messages. So if, for instance, you’re working on a drawing application and your user is dragging that blue circle that they just created when, in a fit of pique, they hit ⌘X with the mouse button still down, your Cut code is going to run, removing the object that your mouse tracking code is trying to move. In a well-written application, things might not break, but it isn’t pretty, and it probably wasn’t what the user wanted to do.

Even if your application gracefully handles this problem, the chances are that somewhere else in your code you’re using the other mouse tracking approach, so the behaviour of your application is very probably inconsistent.

This problem had me worried for a while. All I could find searching the web were solutions like this, which is really ugly and would only really work for tiny applications because you’d end up with all potentially disruptive methods implemented on every view that might be tracking the mouse.

But no, as is usually the case with Cocoa, the solution is quite simple when you know it. All you need to do is something like this (again, the additional code is in italics):

@interface MyView : NSView {
  ...
  BOOL isBeingManipulated;
  ...
}

...
- (BOOL)performKeyEquivalent:(NSEvent *)anEvent;
...

@end

@implementation MyView

- (BOOL)performKeyEquivalent:(NSEvent *)anEvent
{
  if (isBeingManipulated) {
    if ([anEvent type] == NSKeyDown) // Can get NSKeyUp here too
      NSBeep ();
    return YES; // Claim we handled it
  }

  return NO;
}

...

- (void)mouseDown:(NSEvent *)anEvent
{
  isBeingManipulated = YES;
  ...
}

- (void)mouseUp:(NSEvent *)anEvent
{
  isBeingManipulated = NO;
  ...
}

@end

Obviously this is all heavily simplified for the purposes of this post. In a real application, you might want to check the event type, you may not always want to set the isBeingManipulated variable, and you may even find that you want to handle some key equivalents but not others.

November 12, 2007

MT 4.0

Just updated. Comments, predictably, are broken again.

It looks like non-authenticated comments work, and OpenID comments work, but TypeKey comments… don’t. :-(

How frustrating. Anyway, for now, if you have a TypeKey ID, use it with OpenID instead.

November 10, 2007

OK, so I said I wouldn’t… but I did anyway

OK, so I said I wasn’t going to buy an iPhone yet. Yesterday I changed my mind and went to visit the O2 shop in Fareham, where the (very attractive) sales assistants were busy demonstrating the iPhone to the (very short) queue of people at the door.

Worse—for my wallet, that is—my existing phone is pay-as-you-go and I’d only recently topped it up with credit. Why not a contract phone, you ask? Well, quite simply, I’m not part of the current mobile-obsessed culture here in the U.K. and I never really have been. So how do I justify the cost of an iPhone contract? Good question. I’ll have to think on that :-)

Anyway, because of the substantial amount of credit on my old phone, I haven’t ported the number. So if you have my number, you’ll need to update it. Sorry about that.

A few observations about my new iPhone:

  • Mobile Safari has already crashed a few times on me.
  • Mail doesn’t support S/MIME. That’s annoying, because I use S/MIME quite extensively.
  • Mail doesn’t seem to support threading, which is a shame. Maybe I’m just missing the setting?
  • Mobile Safari doesn’t do SVG yet.
  • EDGE is just fine, speed-wise. OK, it isn’t as fast as my home broadband connection, but it’s perfectly usable even for web browsing. I was using it today, as a matter of fact.
  • The Google Maps application really is as good as you’d hope. OK, no GPS, but since you can only really use GPS if you have line-of-sight to sufficient satellites, putting GPS in a phone is of questionable utility anyway. I think people forget that in-car satellite navigation systems contain rather more than just a GPS receiver.
  • The camera is perfectly adequate. If I want high quality photos, I’ll use my SLR thank-you very much.
  • iTunes doesn’t seem to have any ringtones options here in the U.K. right now. I don’t actually want a silly ringtone, so this isn’t a huge deficiency, though I do have a couple of bits of music that would make good non-silly ringtones. And doubtless when we do get ringtone support, we’ll have to put up with the indefensibly silly “a ringtone is something different from playing a section of your music” nonsense here too.

Anyway, it’s very nice and it’s a huge improvement over previous phones I’ve owned.