Must a real coder understand recursion and pointers?

Yeah, as I said, it’s the Big Lebowski problem. He’s not wrong, he’s just an a-hole. As a guy who, in my prior field, was kinda an a-hole because there most definitely was a better way to do and think, I forgive such behavioral foibles a lot if combined with two things:

  1. a proven track record
  2. a focus on the problem, not the person.

Spolsky meets those criteria, but that doesn’t mean he’s not a bit off-putting

I was trained that recursion incurs a program stack cost, but honestly, I was trained when processor cycles and RAM was far more costly (although, with the crunch on NAND flash, RAM prices have stubbornly refused to drop for over a year).

Yeah, that’s the issue with recursion, it works best to divide and conquer on possibly infinitely recursive tree structures and those stackframes build up pretty quick. You need a language that seriously optimises recursive calls to get good performance, and even then you’re generally going to lose out against something that can just overwrite values I guess. That being said, there’s some code I keep a copy of to refer back to when I want to.look at seriously good code, a markdown parser written in OCaml, which is about 200 lines of recursive calls and it is screamingly quick. And the JSON parser library weve started using at work, written in Elixir, is greatly faster than the C library we did use in most cases. Funny thing though, I was watching a talk by the guy who invented Erlang, which is functional, and doesn’t have loops, so you have to use recursion for everything, and he was talking about ways to optimise performance in programs, and he goes the easiest way is just wait 10 years: the hardware will have improved to such a degree that the program will be 1000× faster.

1 Like

No, my point was just that it’s going to be faster in C than it is in JS. In JS, a function call takes up a lot more memory and has to set a lot of things up, and C is much leaner, if I remember correctly. Recursion is still going to incur a hit, but less of one in C so it might be considered a more viable option even when performance begins to become and issue. But I agree, recursion will always be slower/more costly, but recursion can sometimes be an elegantly simple solution to a problem that would be difficult to do without it. Again, I think anything done with recursion can be done without, but sometimes I think the recursion solution is just conceptually easier

Some guy wrote some simple code to test the difference and found the recursion takes about 4 times longer (YMMV).

1 Like