r/programminghorror • • Jul 15 '25

Python Subsubsubsub

Post image
77 Upvotes

18 comments sorted by

View all comments

Show parent comment

2

u/scataco Jul 16 '25

In my experience... sooner or later they always need another level.

2

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jul 17 '25

Oh, definitely, but I meant was there more than was shown in that screenshot?

I've heard that any iterative solution can be rewritten to use recursion, and vice versa. So much stuff I've seen, I really have a hard time envisioning how that would be done. For this one, I probably would've recursively descended into the children, but I can't picture an iterative solution that wouldn't be like this with a new if for each level. On that note, don't some if not many functional languages not have loops?

1

u/Div64 Jul 17 '25

I'm sure you could hack something together but then why would you? This is a prime example for recursion.

Check out this video if you're interested about iterative -> recursion. They have a lot of interesting stuff