Monday, July 02, 2007

The Elevator Problem or Why Writing Software Is So Hard

A lot of people wonder why writing high quality software is so hard. When you read this, you're probably sitting in front of a computer that runs an operating system with millions lines of code. Most people know that a computer "computes", that is it adds numbers all the time and because we define some numbers to mean characters (65 usually means A) or colors (0 is black, 16777215 is pure white, 16711680 is bright green, etc), it can do astonishing things. Like showing you something a guy on the other side of the globe wrote. It's all just math.

As we all know, math isn't simple but 1+1 always gives 2. It doesn't sometimes give 1.9 or 2.2 or 3 or 1. It's 2. Always. That basic observation made many people believe that it must be simple to write correct software. It's just math, after all. It's exact. Well, let me tell you a story so you understand why writing software is so hard and sometimes insane.

Imagine you're working in a big company. Your company is so big, it has its own skyscraper. There are six elevators that carry all your co-employees in and out, every day. This morning, your boss storms into the room and he's obviously very upset: For the third day in a row, someone is using his parking lot. You say, no problem, you'll put a sign in the elevators that the parking lot #5 right next to the elevators is reserved. Your boss is very happy and you can see the next raise shining brightly at the horizon.

So you turn to your computer, fire up your favorite text tool and after a few minutes or hours (depending on the tool), you come up with a nice sign saying to stay the hell away from parking lot #5. A few minutes (or hours) later, your printer has delivered the signs on nice fresh paper. You grab 'em and walk to spread the news in all six elevators. It's the most simple thing in the world to press the button to call an elevator. You wait a few moments (or longer, it's a big building) and "bing", one of the six elevators stops by to get you somewhere.

You smile, step into the cabin and slab the first sign onto the wall. You brought Scotch tape, right? Of course you did. And scissors, too.

The sign looks great. Your boss will be very happy, he will think fondly of you when it's time to spread the good stuff.

So you leave the elevator, let's call it A, wait for the doors to close and press the call button once more.

"Bing" and the door of elevator A opens, so you can take the ride. You start to realize that this simple task might not be that simple after all.

There is a little computer somewhere in the building, that tries very hard to move the elevators around effectively and right now, it's very proud of itself because you didn't have to wait. Now, it eagerly waits for you to tell it where you want to go, so it can take you there as fast as possible. In the meantime, it does the same thing with the other five cabins.

After pondering the situation for a moment, you step inside the cabin and press the button of the floor that is farthest away from where you currently are. The door closes, you wait a moment, so it is really gone and call the next elevator.

"Bing", elevator A opens it's door again.

Apparently, it hasn't moved at all or it can move much faster than you'd think possible. Let us rule out the second option because it probably breaks some laws of physics. You do know that elevators measure the weight of the passengers, don't you? Well, some time ago, smart engineers noticed that kids wasted a lot of energy sending the empty cabins around. That made them angry, they didn't want little pests to toy with their toys. So they used the very same sensor to determine if someone is actually inside and if not, they told the little control computer to just ignore any requests to send the elevator around. Ha! That shows them!

All right, you tell yourself, and go for the staircase to move a few floors down. Slightly annoyed, you press the call button. You wait, "Bing" and ... elevator A offers it's service. Somewhere in the house, a little control computer is very proud that it could send you an empty ride so fast.

Now is the time to start to worry. You could ask your buddies in the office for help. You need five of them, each rides one elevator to some floor and blocks it there. Of course, you know them and you're a bit worried about the remarks you'll probably get before you can explain to them why on earth it could be so hard to stick a piece of paper on an elevator.

Now is also a good time to think what you boss will think when you don't return soon. Surely, to stick six pieces of paper on a wall can't take more then a few minutes? What will he think if you fail even such a simple task?

The morale of the story: Even very simple things can become insanely complex as soon as a computer is involved. Unfortunately, even seasoned developers with years of experience sometimes fail to see all the traps in advance. That leads to the paradox situation that they concentrate on all the "hard" stuff, which they expect to cause trouble and postpone the "easy" stuff. If that easy stuff is hiding a bad surprise, it's usually late in the project when you finally get to it. And at that time, the effects might be tremendous because you made your all your plans and estimates with the idea in mind that the "easy" thing will be a cinch.

That leads to the conclusion that it is impossible to estimate a software project except you have done the very same thing (including all circumstances!) before, preferably several times. If you didn't, your estimates are just guesswork and could be off by several magnitudes (i.e. 10, 100 or a 1000 times).

PS: The solution for the elevator problem is to find the janitor or someone from the cleaning team. They have keys to take cabins out of service (ever noticed the locks near the buttons? That's what they are for), so they can clean or repair them. Or you could paste the notice on the wall next to the parking lot. Or place one under the wiper. But we're computer freaks; simple solutions are for wimps!

2 comments:

Anonymous said...

or move something with weight into the lift.

eg. a bin or a ream of paper.

Aaron Digulla said...

I can readily imagine that:

Boss: "Didn't you have a bin? And what happened to the documents I dropped on your desk yesterday? Are they finished?"

"Uh ... they are on their way!" *lol*