11 ms·
Why? First, loops are only a special case of recursion, and trying to shoehorn everything into that special is actually hard to read. Second, functional progr
by eru 11y ago
Why? First, loops are only a special case of recursion, and trying to shoehorn everything into that special is actually hard to read.
Second, functional programming usually emphasises combinators like map, filter, reduce/foldr. Those are easier to read than either naked recursion or loops.
- coldtea 11y ago>Why? First, loops are only a special case of recursion In theory. In the actual world, loops are how we're used to think about doing N things.
- eru 11y agoIf `we' is imperatively trained programmers, then Yes. For anyone else---normal people without programming experience, or programmers trained in different paradigms---loops are not special. Of course, we mostly talk about programmers here, and imperatively trained programmers are in the majority. In any case, lots of languages have gotten map and filter, and people seem to adapt to them just fine. We just have to wait another decade for the more interesting combinators to trickle down.
- coldtea 11y ago>If `we' is imperatively trained programmers, then Yes. No, we refers to both "imperatively trained programmers", and, more especially, laymen. >For anyone else---normal people without programming experience, or programmers trained in different paradigms---loops are not special I very much doubt any layman who does anything repetitive (e.g. runs 10 laps) thinks of it as recursion as opposed to keeping a mental index and thinking it similarly to a loop (without knowing the terminology of programming of course). >In any case, lots of languages have gotten map and filter, and people seem to adapt to them just fine. Those are just abstracted loops though, not recursion.
- eru 11y agoI'd assume laymen think in terms of combinators, ie like map (do this operation to all the things I have), or filter (through out all the widgets that fail the test). Thinking in terms of indices is pretty painful. > Those are just abstracted loops though, not recursion. Map and filter on a tree is about as recursive as it gets. Loops are the special case of recursion that does work well on linear data structures like linked lists and arrays, yes.
- coldtea 11y ago>I'd assume laymen think in terms of combinators, ie like map (do this operation to all the things I have), or filter (through out all the widgets that fail the test). Thinking in terms of indices is pretty painful. We may think "do this operation to all the things I have" for things that involve the totality of some items as an unknown number (e.g. pack all clothes, take all dishes out of the dishwater). But we also think with indices, and very intuitively, for anything involving a specific number of counts, like the example I gave (run 10 laps, I've run 1...5...7...8...10, done). >Map and filter on a tree is about as recursive as it gets. Well, the original comment was "lots of languages have gotten map and filter, and people seem to adapt to them just fine." And while this might be true for array like collections, I don't think people have adapted 'just fine' to map and filter on trees -- I very much doubt it's commonly used at all.
- eru 11y ago> But we also think with indices, and very intuitively, for anything involving a specific number of counts, like the example I gave (run 10 laps, I've run 1...5...7...8...10, done). Counter-anecdote: Oh, if people were good with indices, they wouldn't have so much trouble with ordinals vs cardinals vs nominals. > And while this might be true for array like collections, I don't think people have adapted 'just fine' to map and filter on trees -- I very much doubt it's commonly used at all. Python's set and dictionary comprehension encapsulate map, filter and cartesian product. But that might strengthen your point: Python goes to great lengths to make these look like loops. I guess we need to get a large number of ordinary people and do experiments on them.