Bruce Eckel's MindView, Inc: 10-22-04 Using Function Objects as Strategies
Bruce Eckel wrote a nice implementation of the old C++ trick called "expression templates" in Java 1.5. It was a decent, and even type-safe, implementation of functional programming using the new generics feature of the language.
However, it took a whole page of source code.
On the comments page for his blog entry, I did a program that did the exact same thing as his example program in just three lines of Python!
>>> def compute(low_boundary, values):
... return reduce(lambda x,y: x*y, filter(lambda low_bound:low_bound>low_boundary, values))
...
>>> compute(4, [1, 2, 3, 4, 5, 6, 7])
210
Which would you rather type on - a page of code or 3 lines?
0 Comments:
<< Home