Pointers and Recursion

7:24 pm PHT

There’s supposedly much ado on Joel’s Spolsky’s article, “The Perils of JavaSchools” (via Tim Bray). The violect reactions seem to come from people who interpreted Joel’s piece as a denigration of schools that teach Java instead of C/C++. It’s actually a denigration of schools that don’t teach pointers and recursion, two things that Joel believes necessarily (though not sufficiently) indicate whether a programmer is excellent instead of just good enough.

I don’t know about you but I don’t find pointers and recursion, per se, hard. With pointers also come the concepts of dereferencing and “address of” operations. I actually found creating and manipulating linked lists in CS11/12 quite fun. Though I have to admit that some people just don’t immediately get it, based on the people I’ve helped debug their linked list programs before. It seems many people don’t get the hang of inserting or deleting items at the start, middle, and end of linked lists.

And, what’s so hard about recursion? While the classic recursive factorial function, which is the “Hello World” to the world of recursion, is not really a good example to the concept, what’s so hard about a function that calls itself? I actually try to avoid recursion especially if you’re not sure how deeply nested the calls are going to be since you might run out of stack space. In which case, I try to do an iterative equivalent and make my own controlled stack space.

In our company, we have an internal ANSI C programming competition where teams of three are given five problems to solve using ANSI C. Many of the problems can be solved using recursion, but I’ve always eschewed it since you’d run out of stack space if you’re not too careful (you’re not given a powerful machine on which to run your programs). In C, not only is the address to the calling function preserved in the stack, but the state of the function is also preserved (i.e., all local variables). If your recursive function has too many data structures (a tendency in the competition), you’d be sure to run out of stack space, especially if the recursion is unbounded. I’ve always gone the iterative route.

Going back to the original article, I agree with Bill de hÓra that one thing that should be taught is concurrency. The concept of concurrent programming helps in my job since we do LSI chip verification, and the tests you create to verify the chip designs need to be concurrent in order to exercise as much of the chip’s functionality as possible.

Filed under

Add your comment | No comments yet


[an error occurred while processing this directive]