#hilarious how like THE example they use for teaching recursion is an ASS-TERRIBLE PROBLEM to solve with recursion
Explore tagged Tumblr posts
Note
I’m sure your oomfs joke is extremely funny but unfortunately my eyes glaze over when I start trying to read code. Let it be known that I have faith in your jokes, though
(context)
non-code-heavy explanation!
sometimes in programming, you'll have a process which is kind of made up of smaller versions of itself.
non-code example: if your task is "read and reply to all unread emails" and you have 100 unread emails. that task is kind of the same as choosing one email to read and reply to, then repeating "read and reply to all unread emails" on the remaining 99 emails. repeat until no emails. (99 bottles of beer on the wall logic)
a common way to do this is with "recursion." a lot of fundamental programming courses teach it because it's a good fundamental. however it's often a poor way to do things, due to computer reasons.
during a recursive task, you "drill down" to do the smaller versions of the task, then come back up. but that "drilling down" can't go infinitely deep. there's a limit to how far down you can drill. and careless recursion can drill really deep and crash the program.
you can avoid all of that drilling if you don't recurse.
my post took a recursive implementation and rewrote it into a non-recursive one.
but the joke there is the original problem was never about recursive-vs-nonrecursive optimization. the original problem was me inventing an infinitely large never-ending outcome. so I swapped one infinitely-large process for a different kind of infinitely-large process. Both of which obviously fail. Just with slightly different flavors.
#recursive calls can also be terrible if you're spinning up multiple versions of the same call on every drill down#so now you're drilling AND multiplying the processes AND possibly calling them redundantly#-shakes my entire two fists at recursive Fibonacci sequence solutions-#hilarious how like THE example they use for teaching recursion is an ASS-TERRIBLE PROBLEM to solve with recursion#Fibonacci sequence my beloved I can solve you via dynamic programming so beautifully
67 notes
·
View notes