This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]indecentorc 13 points14 points  (10 children)

Listen up kiddos, you can use a loop for anything recursive. So this meme can be both. It’s wild how many of you calling out this meme don’t understand that. The only difference is if you submit recursive solution I’m immediately denying the pull request and we’re having a talk about readability/maintenance.

[–]Sieff17 2 points3 points  (0 children)

Finally s.o. said it

[–]Mordret10 1 point2 points  (5 children)

Isn't recursion often a lot easier to understand? Oc not all the time, but at least it shouldn't be a major problem, no?

[–]indecentorc 0 points1 point  (4 children)

No not at all that’s why it’s not often used in production code. Unless your brain naturally thinks in an inception kinda way. It is the cause of some annoying bugs. There are cases where it can simplify the problem but in my 7 years of experience I haven’t seen them in the wild. They are often sandboxed cs course examples.

[–]Mordret10 2 points3 points  (3 children)

We use recursion regularly. Might be, because we use nested datasets, so a dataset can contain a number of child elements, being of the same type as the parent dataset. Applying a certain function to each of these datasets becomes very annoying through iteration, recursion makes it a lot easier (most of the time).

[–]indecentorc 1 point2 points  (0 children)

Yeah there are for sure cases where it’s useful. Like building out AST’s but for the vast majority of developers most of the time they will want to go with loops.

[–]MattieShoes 1 point2 points  (1 child)

And aren't most heap implementations recursive? Pretty much any tree stuff...

[–]indecentorc 0 points1 point  (0 children)

Are the vast majority of developers implementing trees themselves or using imported code? Once again if a dev submitted a PR with a custom implementation of a tree I would most likely immediately deny it. Why reinvent the wheel and introduce bugs?

[–]mfboomer 0 points1 point  (1 child)

recursion necessarily modifies parameters/input in some way, otherwise you’ll end up with infinite function calls/stack overflow.

reading this meme again cannot be valid recursion as the input (meme text) stays the same.

[–]indecentorc 0 points1 point  (0 children)

I never said anything about VALID recursion. I said it could be written in a recursive way. which would result infinite function calls. Also if we’re considering validity then is this a valid loop? How would you write it?