4 ms·
Why Functional Programming Matters
- charlysl 9y agoBut can't higher-order programming and lazy execution be done in OO too? It seems to me, for instance, that Iterators are a form of higher-order programming, because they can be used to abstract all kinds of traversals. Such use is described in GoF. The only requirement for higher-order programming is for a language to have closures (aka function values; this is possible with nested classes). Likewise the Proxy for lazy execution. In GoF it is described how to use it to do on-demand/by-need computations. The fact is that you can do in OO anything that can be done in FP, and then some. It is just that because of this very power you have to be more careful, and use explicit state and concurrency only when really needed, and FP techniques whenever practical. Many GoF patterns are in fact based on this approach, like Composite, Interpreter and Visitor. I am aware that the paper is from 1989, predating GoF by a few years, but the blog post is from last year (love TMP though). It doesn't mention that these techniques have been possible in OO languages for quite a while, although admittedly not built-in and less conveniently.