Tuesday, June 24, 2008

5 minute guide to Algorithms and Bugs

This post is going to be a little different, and maybe a few posts after it also.

I'm going to introduce you, dear reader, to the wonderful world of computer programming! But in easily digestible bite-size bits that will make you want to run out and write your own operating system! Or something.

So let's get started by taking a look at a sample algorithm for chicken pot pie:

  • Preheat oven to 425 degrees F (220 degrees C.)
  • In a saucepan, combine chicken, carrots, peas, and celery. Add water to cover and boil for 15 minutes. Remove from heat, drain and set aside.
  • In the saucepan over medium heat, cook onions in butter until soft and translucent. Stir in flour, salt, pepper, and celery seed. Slowly stir in chicken broth and milk. Simmer over medium-low heat until thick. Remove from heat and set aside.
  • Place the chicken mixture in bottom pie crust. Pour hot liquid mixture over. Cover with top crust, seal edges, and cut away excess dough. Make several small slits in the top to allow steam to escape.
  • Bake in the preheated oven for 30 to 35 minutes, or until pastry is golden brown and filling is bubbly. Cool for 10 minutes before serving.

"No kidding, that's an algorithm?", you say. Yep, indeedy! An algorithm is just a formula for getting something done, and that's really all a computer program is - a set of steps for your computer to follow.

So what if we accidentally left out the crucial final step that says, "Bake in the preheated oven for 30 to 35 minutes..."? In the kitchen, that would be called "plain gross", but in software we would call that a "bug". In 1947, the Mark II Aiken Relay Calculator at Harvard University started acting up, so computer scientist Grace Hopper cracked the lid and discovered, to her surprise, a moth trapped inside.

And ever since, any problems in software algorithms are called "bugs".

No comments: