3 ms·
Higher-order functions do entail a sacrifice to readability compared with plain loops. The reason should be fairly obvious: loops use indentation and syntax to
by rkts 19y ago
Higher-order functions do entail a sacrifice to readability compared with plain loops. The reason should be fairly obvious: loops use indentation and syntax to show visually the structure of what they do, but that goes away when you pack the logic into a higher-order function. A function call is a function call; they all look the same.
Fortunately, there exist solutions to this problem. The Haskell solution is to make your code so damn concise that you don't need to add any structure to it. The Lisp approach is to allow you to program the representation of your code in arbitrary ways.
Both are, I think, superior to the Python solution, which is simply to revert back to the imperative style.
- jkush 19y ago>Higher-order functions do entail a sacrifice to readability compared with plain loops. I disagree with you there. If you understand that Map, Reduce and Filter (for example) are essentially loops, using them greatly increases code readability. Instead of having to read loop code, you're just reading code that describes what you're doing to the data. EDIT: I know this is going to sound weird, but I recently implemented Map, Reduce and Filter in VB.NET. Aside from the fact that using .NET delegates is clumsy, the code portions that use those methods are much more concise (and readable).