Collections and Closures
Martin Fowler (MF Bliki: CollectionClosureMethod
describes the rich library of collection iterators available to languages with closures (also called “blocks”
like Ruby and Smalltalk. as he says, “… the combination of closures and collections leads to some very nice things.”
What he doesn’t quite say, but what I’ve found, is that because these methods are semantically more abstract than “for” and “while”, you end up with code that’s easier to understand. Instead of poring over complex invariants in a while statement, to infer that someone’s trying to pick out the elements of a list that fit some predicate, you just observe a one-line “select” statement.
As I said to David today, as well as being a vehicle for implementation, it’s also a medium of communication with the other programmers who have to work in it. Higher level abstractions serve that need elegantly.
Technorati Tags: coding
Popularity: unranked [?]