Smalltalk by other means
August 01, 2005 |
co.mments
CollectionClosureMethod is one of the best things Martin Fowler has written in a while. Go read it. I love it when he informs through code snippets.
You do get the feeling sometimes the statesmen of the agile community consider the last 10 years of statically typed container backed middleware a distraction from the real goal - the ability to implement business value faster than the business can think it up.
August 1, 2005 05:24 PM
Comments
managers = employees.select {|e| e.manager?}
Here's some statically type checked "Smalltalk by other means"
let managers = employees.select(Employee e => e.isManager);{Collection C, T} C{T} select(C{T} coll, T->boolean test){
C{T} result = coll.similarEmptyCollection();
for (T element : coll)
if ( test(element) )
result.add(element);
return result;
}
Nice and Scala and ... (other statically type checked languages) provide anonymous methods, first class functions, closures.
You do get the feeling sometimes the statesmen of the agile community consider...
Not sure who you're thinking of... but Java sure rained on the Smalltalk parade.
Scala is a sweet language, I once said, and I stand by the statement, that the next language to be Cobol, er, Java, will look an awful lot like Scala.
Of course, Nice already defines useful collection methods...
employees.foreach(Employee e => e.doSomething);
let managers = employees.filter(Employee e => e.isManager);
let managersOffices = employees.filter(Employee e => e.isManager ? e.office : null);
let offices = employees.map(Employee e => e.office);
let allManagers = employees.all(Employee e => e.isManager);
let noManagers = employees.none(Employee e => e.isManager);
let total = employees.foldLeft((int result, Employee e) => result + e.salary, 0);
Post a comment
Trackback Pings
TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1616