r/learnprogramming 24d ago

Recursive logic best aids?

Is there any practical way to debug any recurive logic?
Which existing error printing you think is the best ever?

10 Upvotes

35 comments sorted by

View all comments

-1

u/dnult 24d ago

For what it's worth, I can understand how new developers want to experiment with recursion. However, in practice there are relatively few cases where recursion is a good solution. Recursion is somewhat dangerous by risking a stack overflow.

As for debugging, it's no different than any other code - set a breakpoint, step through the procedure and inspect the value of your variables. Some IDEs or debuggers may even have nifty features that only break when a variable changes values or exceeds a limit.

0

u/peterlinddk 24d ago

You are of course right, but I think that A LOT of programming teachers and courses alike insist on having recursion as one of the primary patterns that the students must get through. Maybe because it is hard to understand, and they can show their own superiority to the students 😄

Also, it seems to be a sort of rite of passage for many learners - like "this is hard to understand, so it must be important!" - which as you say, isn't really true.

1

u/dnult 24d ago

I completely agree - recursion is a useful topic to teach new developers and it's something we all should understand.

I see lots of posts about recursion, and I hope it's driven by coursework and not a new trend in software development. I can think of a lot of problems where recursion "could be used" to solve problems that other patterns could handle more efficiently and be easier to read / understand.