Wednesday, September 17, 2008

Analogies and Computers

Recently, I purchased a book titled How Math Explains the World. It's all gone a bit over my head, but I had a fairly good grasp of the first section, which discussed a few of the unusual and fascinating properties of infinite sets. In order to explain the concepts, the author created a hypothetical hotel with an infinite amount of rooms, numbered 1-infinity, which housed various guests.

As far as I was concerned, the analogy to set up the hotel was wasted paper (although his explanation was fairly entertaining). One of my favorite parts of C++ are arrays. An array is data stored in numbered locations. The numbers start with 0.

0 1 2 3 4 5
7 8 2 4 6 6

If you wanted to access the first location? array[0]. This would give you a 7. You can also store letters, words, sentences, non-integer numbers and more.

Abstract concepts like arrays, so very alien to our ape brain of hunting and gathering, have to be grasped in order to program. You must not program a computer like you're telling a person what to do. Computers are utterly stupid--you must write explicit instructions. The slightest error in grammar or logic will confuse the poor dumb machine until it's giving you numbers like -983454. Not very useful. You have to spell everything out without making any assumptions. At the same time, while you're working on programs that start to get more complicated, there's a truly dazzling number of variations. That's why so many programming concepts make for good analogies.

Let's look at another example of how computer code can help you understand a concept that has nothing to do with computers. Most people have no idea how genetics work. The analogy used in the link is recipes. I think an even better analogy would be computer code. Copy and paste a section of code from one program to another. It could improve it--helping a program that multiplies fractions to reduce the result. It could make the program nonsensical--for example, adding a section of code that uses X as the name for a string when earlier in the program, X was defined as an integer. It could even do nothing.

It isn't just code that provides an analogy. The way our brain stores information--linking memories and knowledge by topic and bizarre, random associations--is similar to Wikipedia and its hypertext. As Max Brooks points out in his masterpiece The Zombie Survival Guide, we in the computer age are better equipped to understand zombies than any other culture. A zombie isn't like an animal. It's like a robot.

int main()
{
bool zombie=true;
while (zombie==true)
eat brains;
return 0;
}

See how simple that is? Even the output of a computer program can help you learn. The world would be a more logical place if everyone were familiar with concepts like loops and if then statements.

Plus, programming is fun. There's nothing more satisfying than looking over a long section of inscrutable gibberish and knowing that it'll perfectly calculate the product of two complex numbers because you were the one who wrote it.

Do yourself a favor. Learn the basics of at least one computer language. It's worth it.

No comments: