I’ve spent the past two weeks working on a program that stores and manipulates data in a binary search tree. This, of course, means I’ve been up to my ears in recursive functions.
For my non-techie friends, it’s the idea that you write a method (a little program that does something) and it calls itself over and over again. And you just kind of have to trust that it works. Trust that a method calling itself over and over again will get the job done. Because you can’t actually see what it’s doing, that would just be silly.
And my point is this–I don’t like it. I much prefer writing programs iteratively. I like writing out all the steps so that I can see each and every one and know exactly what my program is doing and when. It’s the whole “just trust that it will do what you want it to do” that makes me a little edgy.
Hi, I’m Rachel and I’m Type A.
I like to think of the recursive function as the “trust fall” of the programming world. You remember those? In all office-type tv shows, there’s a company retreat where some overly sentimental counselor makes the employees turn their back on each other, close their eyes, fall back, and trust that a random person will catch them. All in hopes that people will get in touch with their feelings, bond with each other, work better as a team, and make the company more money. Humbug!
My recursive functions CONSTANTLY fail. And I feel just like someone who closed their eyes, fell backwards, and woke up with a concussion about 4 minutes later.
How does that happen? I was 2 feet away from the person. They were directly behind me. The instructions were clear—it’s not like they didn’t know I was going to fall into them. This is not supposed to be complicated! And yet, I somehow ended up on the ground.
Next step in the process: I have to look at the situation and try to figure out why this happened. It’s not as easy as it seems. It’s not immediately clear because I had my eyes closed and couldn’t see anything. Also, nobody can talk to me about what happened—that would just be too easy.
You might find yourself saying “Rachel, clearly a gale force wind came out of the west and pushed you out of the way” or “Naturally, the person who was supposed to catch you was highly allergic to bees and they saw one on your back. So, of course they didn’t catch you.” Both of those scenarios are completely reasonable, I assure you. And so I do some research, try to figure out which of those completely plausible factors is the culprit–and then I have to find a way to make it so it never happens again.
Naturally, I do the only reasonable thing: I move the retreat activity into a hypoallergenic clean room with no windows. And if I do the trust fall here, I can trust that the other person will catch me, right? The answer to that question is a firm “maybe.”
And this is what coding is like (at least when I do it).