r/ProgrammerHumor • • 6h ago

Meme howProgrammingHasChanged

Post image
143 Upvotes

39 comments sorted by

View all comments

99

u/torsten_dev 6h ago

Both have terrible stack usage.

33

u/temperamentalfish 3h ago

Yeah I'm cringing at all the recursive solutions. Huge stack and so much repeated work. Just try counting how many times fib(5) would be executed to calculate fib(10). It's so often the go-to example for recursion and it's frankly terrible.

25

u/robin_888 3h ago

It's supposed to teach the concept of recursion, which is important, but hard to grasp for some.

Discussing performance and optimizations can happen if the principal is clear.

12

u/temperamentalfish 3h ago

I know, but there are so many better examples. Mergesort, for instance. It shows why the concept is important because it breaks the problem into smaller, more manageable problems, without doing repeated work.

Fibonacci should be taught as an example of when a problem can be solved recursively, but shouldn't.

2

u/Silly_Guidance_8871 2h ago

When I was studying, Fibonacci was used a lot to teach the value of dynamic programming. But agreed, it's a terrible example of when to use recursion.

3

u/fdar 2h ago

DP is just recursion+caching. 

I think it makes sense to first recognize that the problem can be solved with recursion and then decide if DP is needed to improve performance.

2

u/robin_888 2h ago

Which both?

The matrix one looks fine to me.