« Predictions for 2004 | Main | Jabber and alternate REST architectures »

Functional wannabe

The "ruby way" has started to rub off on my Java personality, specifically in the realm of iteration. I've used a ruby-inspired specialization of the Command pattern (GoF) three times this past week to simplify iteration.Bob Lee

Ruby way, Python way, Smalltalk way, Lisp way - take your pick :) See also:

For a full treatment of where Bob's (neat) hack ends up.

The amount of Java code I (and everyone else) produces just for looping over collections and arrays is considerable, so any idioms that reduce the verbiage are welcome. And yes, Java IDEs will auto-generate iterator blocks - that's not the point. The point is we didn't need all those iterator blocks sprinkled about to begin with. In other languages we have map()/filter()/reduce() and lambda builtins to do the lifting for us. In Python large amounts of code vanish when map/lambda combinations are used; you just have to be thoughtful in handling exceptions mid-loop. A colleague and I looked at a Python application a while back and we figured on maybe a 15-20% line count reduction if functional idioms were used instead of for loops. In Lisp "for" is very much an alien construct. But it's when you start working with headed lists that the block/closure stuff becomes truly powerful.


January 2, 2004 09:12 PM

Comments

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1128