this post was submitted on 17 Mar 2025
39 points (100.0% liked)

Programmer Humor

21852 readers
1069 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 

Please leave recursion to math and keep it out of (in particular C) software: it kills and will kill again.

Kind regards from libexpat, see CVE-2022-25313 and CVE-2024-8176 for proof.

https://blog.hartwork.org/posts/expat-2-7-0-released/

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 4 points 6 days ago (1 children)

Tail recursion in particular is usually just turned back into a loop at the compiler, and typical modern architectures implement a call stack at the hardware level, which allows you to do limited-depth recursion, but breaks like in OP if you try to go too deep.

Yes, in my experience this is what the term "recursion" means in a programming context; it doesn't usually refer to a mathematical ideal. That was what tripped me up.

[โ€“] [email protected] 2 points 5 days ago* (last edited 5 days ago)

The basic definition would be something like use of a function in that function's own code. It's pretty easy to find examples that aren't tail-recursive specifically, like mergesort, and examples within those that would overflow a hardware stack, like in OP. And that's without looking at (mildly) exotic examples like the Ackermann function.

Basically, the "Please leave recursion to math and keep it out of (in particular C) software" in OP means don't define functions using those functions. It's pretty and it can work, but not reliably.