Archive for the ‘Software Development’ Category

A nice take on the apples-and-oranges puzzle

Friday, July 30th, 2010

Richard Wiseman has a nice retelling of the apples-and-oranges puzzle (which incidentally was a regular interview question at a company I used to work for):

Yesterday I saw a drinks machine that had three selections – Tea, Coffee or Random (Tea or Coffee).  However, the machine was wired up wrongly so that each button does not give what it claims. If each drink costs 50p, what is the minimum that you have to put into the machine to work out which button gives which selection?

What I like about this is that it makes more natural several of the constraints of the original puzzle (a crate of apples, a crate of oranges, and a mixed crate):

  • Why can’t I just peer into the crate and look at the contents?
  • Why only draw one fruit at a time?
  • Why do I care how many fruits I have to sample?

It also makes more sense of the effectively-unlimited supply of fruit that is implied by the question: if it’s the wiring that’s at fault and not the hopper of tea / coffee, you could refill it as many times as you want without affecting the wiring.

The puzzle, of course, hinges on the listener not paying attention to the crucial fact: the wiring for each button (or the labelling on each crate) is known to be wrong, not just unknown. It’s one of the neat things about this puzzle that an intelligent solver may well mishear it, but can easily prove it’s impossible if the wiring is entirely unknown. In point of fact, it’s a fairly simple to show that if it is possible, then the answer must be one: we can’t necessarily distinguish a random stream from a constant stream with any number of samples. Constructing a proof that one sample will suffice is fairly easy, given that there are only three possibilities of which to sample, and by symmetricity only two possibilities that differ.

Does this make a good interview question for a software developer? I’m not at all convinced it does. It feels like a meta-puzzle: you reason through it by knowing the implicit rules of the game of puzzle-writing (one obvious one being that the answer can’t be impossible, and it can’t rely on luck or “good enough” solutions like 1000 random samples). Good software engineering often involves judgment calls where such rules don’t exist, and great software engineering often involves rethinking the rules of the game entirely.

Debugging in the real world

Friday, July 30th, 2010

As part of my preparations for living in Zambia, I’ve had to have some vaccinations. One of the recommended vaccinations was Hepatitis B. Luckily, the UK National Health Service provides Hep B vaccinations for free. Unluckily, they also provide Hepatitis A vaccinations for free, and the two are delivered as a combined vaccine. I’ve already been vaccinated for Hep A, so I can’t have the combined shot. This means I have to have the single Hep B vaccine, which isn’t free.

It seems odd that having immunity to a disease should drive up my costs for getting vaccinated for another disease. It seems downright bizarre that my making it easier (or at least, no harder) for the government to deliver the free service should mean I have to pay. It would be fashionable at this point to rail against the fundamental inefficiency of government-provided healthcare.

But I don’t think that’s what’s happening here. The mistake the NHS seem to be making here looks like the same sort of mistake that is made every day by thousands of software developers. The set of rules for Hepatitis has a bug in it (no pun intended).

It seems to me that in this case the bug is a leaky abstraction. The obvious goal is to provide immunity to both diseases, and a policy of providing a combined vaccine looks from a high level as if it fulfils that goal. When the details of the policy are implemented, an obvious refinement is not to provide a combined vaccine to someone who’s already had one shot (whether this is a matter of health or cost-saving I don’t know, but it doesn’t affect the argument).

Obviously this is an over-simplification; looking at the world through the eyes of a programmer, things naturally form into shapes and idioms that are common currency to the techie. But I think this there’s something to be gained from seeing the world this way. When people try and build rule sets, they get things wrong. Not because they are stupid, or unwilling, or corrupted, or bureaucratic, but simply because creating perfect rule sets isn’t something that humans are naturally capable of.

Why is it so hard to report a bug?

Saturday, July 3rd, 2010

Not so long ago I had a misunderstanding with a colleague, who I’ll call Bob. I received a routine request for technical support from Bob, to which I replied immediately with a clear but brief explanation of how to solve the problem. An hour later, I got a slightly testy email from Bob to say that his problem still wasn’t fixed, and it was really holding him up. I double-checked that the proposed solution worked, silently cursed Bob for being too simple to follow my instructions and pinged back an email with a longer and slightly more patronising set of instructions. Two hours later, a furious email from Bob, copied to the CEO. Didn’t I understand how important this issue was? A critical project was in the balance, and I hadn’t fixed his problem.

The punch line? Bob’s email hadn’t been working all morning, and nothing I sent had got through to him. Bob’s emails read to me as if he’d got my instructions and somehow failed to follow them correctly, so it looked to me like he was being inept. From Bob’s point of view, I was giving him stony silence that could only be explained by a lack of motivation.

I’m sure this kind of problem has been plaguing the interactions between technical and non-technical people for as long as there has been technology to bicker over. Users complain about bugs that don’t get fixed, while techies whinge that the users misdescribe their problems, foul things up further with misguided attempts to fix them and then fail to follow instructions when they get them. Why isn’t it going away as people get more tech-savvy?

Behaving correctly when you encounter a fault and reporting it in a productive way is a reasonably subtle task; Simon Tatham’s piece on how to report bugs effectively is a very approachable and effective guide, but it’ll probably only ever be read by the motivated. Even so, you might think that sheer trial and error would teach people that certain ways of reporting a bug get the solution they’re after more quickly than others.

Some people suggest that we techies are lacking in communication skills, and that we need to work harder at making ourselves understood in order to engage with the modern workplace. This isn’t entirely without merit, but I think it’s facile. I’ve been lucky enough to work with some very articulate developers, and none have been immune to this kind of misunderstanding.

I think there’s something deeper going on here, and I think it lies in psychology. The fundamental attribution error is the observed effect that people tend to attribute other people’s behaviour disproportionately to their character, neglecting the possibility of simple situational explanations. For example, I attributed Bob’s inability to solve his problem to his not taking the time to read my instructions properly, or being too poorly-skilled to put them into operation. All the time I was building up in my head a picture of Bob as an incompetent, over-confident bumbling oaf who shouldn’t be trusted to go near a keyboard—and all because his email wasn’t working.

But it goes the other way too. I’ve no doubt Bob had painted a picture to himself of me as an uncommunicative nerd who didn’t appreciate the importance of Bob’s project to the business. Neither of us even considered that there might be an alternative explanation.

The thinking that leads to the fundamental attribution error makes some sense, when you think about it. When you’re dealing with someone on a casual basis you can come to great harm by not making an assessment of their character, and assuming that any flaws you observe are likely to hurt you again in the future is a sound defensive position. This might lead to missed opportunities in casual acquaintances, but that could be a price worth paying.

This thinking is catastrophic, though, when it becomes an entrenched pattern that prevents the very nature of the problem from being properly understood. Blaming developers for being aloof, or users for being incompetent, only reinforces the stereotypes. Working on our communication skills only helps if the thoughts we communicate are based on the right model.