Overwhelmed

I'm going to clean my room today. It's not like there's food and wrappers and dirty plates all over the place, but there is a lot of computer stuff lying around, and soda cans. But, I look around and I'm like "F#@%#$@!!!" That's all I can mutter. But, then I just remember the definition of recursion

an expression such that each term is generated by repeating a particular mathematical operation

So, WTF in the WORLD does that have to do with cleaning my room? Simple. Well, let me break it down into a function.

int removeItem(Item[] items){
if (items.size() == 0) return 0;

items[items.size()-1].remove();
return removeItem(items);
}

As you can see, it's all about performing the same action, over and over again, but with a twist. Recursive functions call themselves. It's a very neat way to think when you're writing a program, and once you start to "think recursively", which I have to admit took me a few months in school, then you start to always think recursively, which is why I post this entry. So let's look at the program.

public void cleanRoom(){
Item[] items = ;/// get items from "Room" database
removeItem(items);
}

So, calling removeItem once will clean your entire room. Of course you could just have a "for loop":

for (int i = 0; i < items.size(); i++){
items[i].remove();
}

This gets into asynchronous access issues, array indexing issues, and everything that I just don't want to have to deal with when cleaning my room. You would have to reverse the loop, from items.size() to 0, and it's just too much thinking for something that shouldn't take much thinking at all. Grab item, throw it in trash bag. That's it. I'm not thinking any more than that. Thinking's stupid.

Thinking this way helps me to not feel overwhelmed. It's just one action, repeated over and over again, until the room is clean. And, the room will be clean when I cannot repeat the action any further, when there are no more items. Or when I'm passed out on my bed under a pile of computer game and parts boxes, and shoeboxes, coincidentally. That helps me as well as putting on my favorite tunes from Jimi Hendrix and Cracker. This is going to rule.

Hopefully you've learned a bit about recursion and computer programming, and how someone can think about this stuff all the time, except when they're trashed. Get it, trashed?! I kill me.

blog comments powered by Disqus