▲ | fellowniusmonk 2 days ago | |
Yngve depth is how many things your brain has to keep open at once when reading code. More nesting and overlapping, center-embedded obligations in recursive code (especially side effects) raise that load, independent of Big-O. Recursion isn’t a hardware thing; it compiles to iteration, so the trouble comes from how the code is written, not recursion itself. Optimizing for Kolmogorov complexity can make code shorter yet harder to parse, so naming and linearizing steps adds bytes but lowers the mental stack. Which is why heavily recursive code get's less optimization attention in most instances than loops. | ||
▲ | bjoli 2 days ago | parent [-] | |
I find recursion clearer in many cases, even simple ones. Like, say, calculating gcd. The recursive approach uses one variable less, and expresses it in a way that is much closer to how I think about it. |