if (sickAndTired==1) return sickAndTired(1);

Yeah I know the pseudocode above looks like crap. I'm ill. Sue me.

The beautiful thing about recursive functions is how spare they are. Since my math never got past first derivative calculus, I wasn't introduced to the notion of functional recursion until taking Algorithms and Data Structures in graduate school. The concept seems cute, at first: normal functions process data and then return a value to the program which called them. If they need to perform some extra manipulation on the data, they call subroutines. Recursive functions embed the nature of the subroutine in the function itself,so instead of exiting out to another chunk of the code, the recursive function calls *itself* to do the processing. Done correctly, it means you can use one or two lines of code to manage what would have taken a half dozen subroutines. It's tight.

So there I was this morning, suffering from flu, and going over the old saw about "I'm sick and tired of being sick and tired" when I realized I was sick and tired of that saying. Then I saw that my very bitterness about the phrase was making me feel worse, so I was sick and tired of that. A recursive function.

Here's the rub: a recursive function needs a proper "exit condition," or the incautious coder will end up with an endless loop which will just cause your program to churn over the same lines, over and over, until you use up all available memory and crash out. That's what's up with me: my very annoyance at my illness is making it harder to recover from the illness, as I burn calories and fret awake all night instead of resting, which leads to more illness, etc., etc.

Illness: a recursive function with a bad positive-feedback loop. I blame the coder.
 •  0 comments  •  flag
Share on Twitter
Published on September 09, 2012 15:00
No comments have been added yet.