Archive for November, 2009

Two kinds of harm

Saturday, November 7th, 2009

In all the furore over the UK government sacking one of its advisors for criticising policy, I think there has been some misunderstanding. None of the sources I’ve seen has been able to pin down exactly which of Professor Nutt’s statements ultimately led to his dismissal, but one that the media have focussed on is the statement that taking Ecstasy is less dangerous than riding a horse. Since my argument doesn’t depend on the specifics of the claim, I’ll take this as an example.

It seems to me that in making a statement like this, Professor Nutt is speaking about the risk of physical harm to the person undertaking the activity. This kind of statement is well within the professor’s area of expertise, and I have no reason to doubt its veracity. Various people in the government have attempted to play this statement down, quibble with it or sweep it under the carpet, and I believe they are wrong to do so. This statement is a verifiable matter of fact, and if it is wrong we should be able to produce sufficient evidence to contradict it. Assuming it is correct, it is also a pertinent observation in setting out drug policy.

There is another sort of harm though, which drug policy needs to take very seriously: the issue of harm to a society. I’m thinking here of the difference between a society where people are happy and benefit from their interactions with others, and a society that thwarts people’s ambitions and harms their development.

It seems to me that society is a system that is complex beyond any one person’s understanding, and full of feedback loops and non-linear effects that can make unintended consequences irrevocable. This would support caution in decriminalising substances even where the risk of physical harm were small, since we don’t know whether decriminalisation will increase or decrease consumption, nor the effect of having a greater or lesser number of people experiencing altered states of mind.

Ecstasy and cannabis have the potential to do harm to society in the same way that television and the internet have harmed society—and the potential to help it as well. We don’t have the luxury of choosing whether drugs exist, only whether we use criminal punishment or not, and neither stance is obviously correct. If we wish to work out which is which is the best path we need a robust debate, and sacking advisors is not the way to achieve that. If the key difference in opinion is that Professor Nutt was talking about physical harm, while Alan Johnson wishes to emphasise social harm, then the latter ought to say so.

O’Reilly gets it wrong

Friday, November 6th, 2009

O’Reilly’s Safari service provides access to thousands of books online, instantly, for a reasonable fixed monthly price. It’s a fantastic service for people like me who are frequently learning new technologies and working from a number of different locations. It’s such a good service, in fact, that even when they’ve ruined their web site and done everything they can to annoy their customers, I still can’t imagine giving it up.

Safari’s original service was to provide the text of the books in HTML form. Recently they launched a new version of the software, which does away with plain HTML and forces the reader to use a Flash-based viewer, providing reasonably faithful replication of the pages of the book but making plain text harder to read.

O’Reilly did just about everything wrong that they could have done with the launch. The new software is buggy to the point of being almost unusable, with navigation broken and corrupt and missing content commonplace. Despite the fact that this was a feature nobody asked for, the old (and bug-free) way of browsing the content as HTML was disabled as soon as the new feature went live. When customers protested that they found the new interface harder to use and preferred the old one, O’Reilly chose to argue with their customers and tell them why they were wrong. Reports of intermittent bugs are frequently met with “works for me”, with customers being forced to act as unpaid (in fact paying!) QA staff to reproduce bugs and provide evidence.

There’s a lesson in here somewhere. Safari isn’t Twitter, it’s a service that professionals pony up substantial amounts of money for on a monthly basis, and when people continue paying they expect to continue to receive the service. The fact that they have no direct competitor is the only thing saving them from a mass exodus at the moment, and most online services aren’t so lucky. The customer may not always be right, but they are never worth arguing with.

Customising sort order in MySQL

Thursday, November 5th, 2009

I came across a situation the other day where I needed to sort my result set in the database for efficiency: we were selecting a small number of a very large result set, so sorting on the client would require the entire data set to travel over the wire. Unfortunately, the requirements of the front end weren’t compatible with MySQL sort order, since the customer wanted empty strings sorted to the bottom of the list.

In other words, I wanted to be able to do something like the following:

  SELECT id, name
    FROM people
ORDER BY name
   LIMIT 20;

and end up with the result set

id name
3 Alice
7 Bob
4

Changing the schema wasn’t an option, and nor was doing the majority of the sort in MySQL and post-filtering, since that would cause the wrong number of results to be returned after some had been shuffled to the bottom of the list. Luckily, there’s a quick hack in MySQL that allows this sort of thing to be done:

  SELECT id, name
    FROM people
ORDER BY FIELD(name, ''), name
   LIMIT 20;

This works because the FIELD() function returns the index of the name value in the list of fields given, and 0 if it is not present. That is, if the name is an empty string, this expression will return 1, and if not it will return 0. This causes empty strings to be sorted to the end of the list as desired.

Note that this prevents an index from being used for the ordering, which may be a problem depending on the size of the result set. In my case, the query was such that an index couldn’t be used anyway, so there was no substantial loss of efficiency.