News for hackers. Stuff that matters.
Re:Recursion is lying to you by RajT88 on Tuesday July 28, 2026 @04:44PM (#49089673)
CS 101, no? Recursion is easier to write, but less performant and more risky than iteration.
Re:Recursion is lying to you by valleyer on Tuesday July 28, 2026 @04:54PM (#49089771)
It's not CS 101 that JavaScript apparently sucks at TCO. That was surprising to me.
Re:Recursion is lying to you by dnbfbfhf on Tuesday July 28, 2026 @05:05PM (#49089898)
The CS 101 model of computing doesn’t have TCO… which makes it pretty accurate to the real world.
Re:Recursion is lying to you by ckcheng on Tuesday July 28, 2026 @06:07PM (#49090587)
TCO is surprisingly commonly supported in the real world. TCO is supported in C++ compilers, JavaScript in Safari, Scala, Clojure in a way, etc.!

For instance:

"All current mainstream [C++] compilers perform tail call optimisation fairly well (and have done for more than a decade), even for mutually recursive calls" [1].

"As of July 22, 2023 Safari is the only browser that supports tail call optimization" of JavaScript [2].

"Since Clojure uses the Java calling conventions, it cannot, and does not, make the same tail call optimization guarantees. Instead, it provides the recur special operator, which does constant-space recursive looping" [3].

"The Scala compiler will automatically optimize any truly tail-recursive method. If you annotate a method that you believe is tail-recursive with the @tailrec annotation, then the compiler will warn you if the method is actually not tail-recursive" [4].

[1]: https://stackoverflow.com/a/34129

[2]: https://stackoverflow.com/a/37224563

[3]: https://stackoverflow.com/a/34097339

[4]: https://stackoverflow.com/a/3114245

Re:Recursion is lying to you by ignoramous on Tuesday July 28, 2026 @06:24PM (#49090801)
Heh, reminds me of this talk at !!conf: Tail Call Optimization: The Musical, https://youtu.be/-PX0BV9hGZY (2019).
Re:Recursion is lying to you by sras-me on Tuesday July 28, 2026 @04:54PM (#49089774)
>Recursion is easier to write

And read..

Re:Recursion is lying to you by LPisGood on Tuesday July 28, 2026 @05:51PM (#49090404)
You’ve never read a 5000 line recursive method that returns different numbers of arguments depending on where it chose to execute the recursive call.
Re:Recursion is lying to you by palata on Tuesday July 28, 2026 @05:54PM (#49090427)
Bad code is hard to read, that is orthogonal to the fact that it is recursive.
Re:Recursion is lying to you by tikhonj on Tuesday July 28, 2026 @06:27PM (#49090829)
If all you do is replace the recursion in that example with one (or more) loops with mutable indexes, chances are the code will get worse.
Re:Recursion is lying to you by LPisGood on Tuesday July 28, 2026 @06:33PM (#49090890)
Oh don’t worry it had more than a half dozen of those nested as well
Re:Recursion is lying to you by veqq on Tuesday July 28, 2026 @04:57PM (#49089804)
Risky?
Re:Recursion is lying to you by makr17 on Tuesday July 28, 2026 @05:07PM (#49089921)
Presumably stack depth and overflow.
Re:Recursion is lying to you by mypalmike on Tuesday July 28, 2026 @08:59PM (#49092113)
I once wrote a Xbox 360 indie game that would crash only in unusual situations due to stack overflow. The game involved essentially gluing together balls, and it would detect if the balls surrounded something. I used recursive DFS to check connectivity of the balls. And most of the time, there would be a couple dozen balls max connected. But you could definitely intentionally connect many many more balls if you wanted to. At a certain point, it would crash with a stack overflow. Changing it to not use recursion (explicit data structures) fixed the crash.
Re:Recursion is lying to you by dreamcompiler on Tuesday July 28, 2026 @10:23PM (#49092743)
Tail recursive functions on a tail-jump optimized compiler can be as performant as loops. If the compiler was written by someone who has read the Steele papers, it generates the same assembly code in both cases.