Re:Ask HN: Is Recursion Worth It?
by dieselgate on Friday January 27, 2023 @12:04AM
(#34542694)
Thought you were going to say “knowing when Not to use recursion” is important.
It’s a handy concept and tool but not practical/relevant for a lot of real world/day to day stuff.
And of course there’s the obligatory joke:
What’s the B in Benoit B Mandelbrot stand for?
Benoit B Mandelbrot ;)
> Bad CS teacher
Most definitely. OP should get into a different class or university. I'd be concerned about the program generally if someone is teaching these ideas
> Bad CS teacher.
You don't know. Maybe she wants them to recognize and use folds whenever possible, rather than using low level recursion all the time. You know what they say: "Someone has to write recursive functions, but it does not have to be you!"
Re:Ask HN: Is Recursion Worth It?
by 082349872349872 on Friday January 27, 2023 @01:06AM
(#34543104)
CS departments come in two flavours: systems and theory. The more dogmatic of each both eschew recursion, but have motivations that are diametrically opposed. :)
Re:Ask HN: Is Recursion Worth It?
by mrnonchalant on Friday January 27, 2023 @01:29AM
(#34543249)
What are the reasons?
Re:Ask HN: Is Recursion Worth It?
by 082349872349872 on Friday January 27, 2023 @01:43AM
(#34543323)
As given above: in a dogmatic systems department, recursion is to be avoided because its naive implementations use more machine resources than their equivalent loops; in a dogmatic theory department recursion is to be avoided because it is more difficult to prove properties of potentially unstructured recursions than of structured folds.
The dogmatic systems department wishes to replace recursion with something more concrete; the dogmatic theory department with something more abstract.
we can form a committee from both departments, and after enough iteration, they may agree to a compromise that annoys everyone equally: replacing recursion with recursion.
It is a useful tool. Knowing how to do recursion is better than not knowing.
> My CS teacher told me to avoid recursion when possible.
Bad CS teacher. There are some algorithms that are much more elegant and easier to build in a recursive manner (i.e., walking a tree being one).
> Apparently recursion takes up more memory space than nested for loops (I'm talking about 4-5 for loops) and I lose grades for the same.
That really depends upon what local variables the recursive routine allocates. But, unless you are studying for building embedded systems with seriously constrained memory space, the difference in memory is negligible in today's typical systems with gigabytes available. And an easier to understand algorithm in recursive form would outweigh a difference in memory usage anyway.
> I lose grades for the same.
Again, bad CS teacher. Unless the problem statement explicitly indicated to not use a recursive routine, a recursive solution should be graded on whether it fulfills the rest of the problem statement requirements, not on the mere fact that it is recursive.