3 ms·
The only difference there is whether the "wrong answer" is visible while it's being calculated. Sums and factorials are the worst possible way to teach recursi
by TheOtherHobbes 4y ago
The only difference there is whether the "wrong answer" is visible while it's being calculated.
Sums and factorials are the worst possible way to teach recursion because they look like a loop with a weird twist that adds conceptual complexity but doesn't seem to be there for any other reason.
Recursion should really be taught by application to complex nested data structures. It's a lot clearer when you apply it to structures with multiple sub-levels that can be processed identically than with a simple linear list or range.
- dandeere 4y agoTrue. But functional programmers will down vote you.
- hurril 4y agoIt isn't, though. I recently started learning Rust and've basically been having to teach myself loops again. For over 10 years, I've not constructed a single loop; I've been getting it done by constructing my program with different combinators and recursion instead. And I've not ever felt that what I'd done would have been better with a loop. It's even very seldomly that I even need if-statements. It's clearly a difference and I really would like to think of myself that I'm not _that_ deep into the cool aid. This has been done with Scala, F#, Haskell and Elm. With Rust, not only do loops feel more natural, they're very clearly the right tool.