Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I could see this being an issue with C++. gcc likes to take recursive functions and turn them into loops when compiling. So the space used would be small for stack variables. Which compiler used might make a difference.
-
iiii90853y@Demolishun and are easy to remake into loops as well. Just add some fake stack and done.
-
@iiii
Actual functional languages do tail call optimization. Tail-recursive functions are compiled as loops there.
In such functional languages, you are allowed to write a recursive solution as a tail-recursive function. You don't need to convert it to a loop by hand.
And sometimes a recursive solution is easier to read and understand. -
hjk10156963y@iiii I'm very interested in how that works. Can you show me an example
with the classical filesystem traversal problem? -
hjk10156963y@iiii https://rosettacode.org/wiki/...
Or pick any other language example with a recursive walk function actually visible. -
hjk10156963y@iiii thanks didn't know what you meant with fake stack but makes sense now.
I was thinking along the same lines with building an itterable datastructure. -
bioDan56223y@iiii good luck trying to parse languages without using recursion.
Doable? Maybe.
Maintainable? No way. -
@GeorgeBool I find some problems are much easier to reason about with recursion. Also, why spend the time making it non-recursive? If you structure it with a tail call the compiler can do whatever it likes with the code. The place I use it the most is trees.
uSE AnY pRogrAmMinG L@ngu@g3 yOu liKe.
1nTervi3weRs Do N0t CarE aBouT tHe L@nGuAge.
Fuck you. Stop asking time complexity or space complexity of functional code. No one fucking knows.
rant