Now that BHurt has done a nice job talking about why Laziness is cool, I’ve got a bit of an ax to grind.
The problem I have is that Java all but completely fails to be lazy, which is a shame considering how useful the trick is.
The Sun team themselves seem to be of the opinion that functional programming generally isn’t something one should be doing. The core library has a complete lack of functional support, and so those who want to use functional coding methods are delegated down to defining lots of interfaces and inner classes, which really clutters up the API and looks ugly. C# did a somewhat nicer job by basically stealing C++’s “function pointer” concept, and I’d like to see Java implement it eventually.
The bigger issue is that even in the Jakarta Commons framework, there is no implementation as Brian described it. What they have as a “LazyList” in Jakarta Commons-Collections isn’t terribly useful: instead of generating a “next object” like the theoretical lazy list does, it generates an object based on no input (not even the index of the array!). There isn’t a way to wrap a List in a series of lazilly-evaluated (get-time) transforms: the TransformedList is all put-time. There is no “next-function-based” Iterator. The two major useful pieces of lazy functionality they do have is the TransformIterator (which does enable you to chain transforms at get-time) and the LazyMap (which enables transformation-based lazy generation).
Now, there is work that can be done to extend the Commons-Collections to implement that kind of functionality, but I haven’t even begun to test the waters to see if it would be something the core development team would be willing to accept. I’m a bit busy devoting my free time elsewhere, so if someone else would pick up this ball and run with it, I’d love to see it in. Otherwise, it’s something I’ll get around to whenever I get back to spending my limited free time on Java work.
Related posts:
Pingback: Enfranchised Mind » Java and Lazy Lists: I Stand Corrected (Sort Of)