r/ProgrammingLanguages • u/gofl-zimbard-37 • Jan 18 '26
Why not tail recursion?
In the perennial discussions of recursion in various subreddits, people often point out that it can be dangerous if your language doesn't support tail recursion and you blow up your stack. As an FP guy, I'm used to tail recursion being the norm. So for languages that don't support it, what are the reasons? Does it introduce problems? Difficult to implement? Philosophical reasons? Interact badly with other feathers?
Why is it not more widely used in other than FP languages?
76
Upvotes
View all comments
Show parent comment
1
u/tmzem Jan 19 '26
One can argue that this is even worse. When I was learning some Haskell I implemented some basic iteration construct and was very surprised that some code not in tail position didn't crash with a stack overflow. I had to open a system monitor to see the code i wrote was consuming GBs of memory for no reason. How exactly can you do any practical programming when you cannot determine the correctness of your code in testing but need to externally measure memory consumption? Even if you get your tailcalls right, how can you guarantee that a innicent-looking refactor won't break it in the future?