4 ms·
I'm surprised by the hostility in the comments. Also, everybody's focusing on closures, which makes sense given the article, but I think the main point is abou
by tikhonj 15y ago
I'm surprised by the hostility in the comments.
Also, everybody's focusing on closures, which makes sense given the article, but I think the main point is about higher-order functions which require first-class functions (what the author calls closures).
Using higher-order functions in place of loops is much like using structured programming instead of goto.
A for loop is just a specialized form of goto that makes what its doing more explicit, lowers spaghetti code and makes making mistakes harder.
A fold or a map is just a specialized form of a for loop that makes what its doing more explicit, lowers spaghetti code and makes making mistakes harder.
Everybody decrying the article would probably never dream of using gotos for control flow--structured programming is patently superior! And yet you are also reluctant to use higher-order functions.
I think this is a perfect realization of PG's ideas in his Blub essay.
- deleted 15y ago[deleted]
- krakensden 15y agoI can't speak for everyone, but I'm hostile because I have read it a hundred times before. A nontrivial number of programmers discover functional programming and then write identical blog posts with identical trivial examples.
- tikhonj 15y agoThe problem is that nontrivial blog posts are only going to be interesting for people who already like functional programming. Since people liking functional programming are not doubt a minority on HN, you're going to see far fewer articles like that. Coincidentally, I remember when I was first learning Perl, then C++ and then Java, a lot of the stuff I read was far more evangelical about OOP.