BT

Functional Programming in Java with Generics and CGLib

| by Floyd Marinescu Follow 38 Followers on Jul 03, 2006. Estimated reading time: 1 minute |
Those interested in Functional Programming usually have to use a well suited-language like Scheme, Haskell, Ruby, or Groovy; or, in Java, use Anonymous Inner/Local classes to fake it like commons-collections. Ray Cromwell has a method for doing FP in Java using Generics and CGLib, reducing overhead and preserving type information for better use in IDEs integration:
Our goal is to try and make writing functions as easy as possible, and allow them to be curried, composed, and passed as arguments to other functions. Functions, as used in this article, are not just any old Java method. They are Java instance methods which are pure-functional, that is, without side-effects, and do not reference any object fields or non-static variables. Essentially, they are non-mutating static functions declared without a static qualifier.
In the essential read Why Functional Programming Matters, John Hughes argues that functional programming significantly improves modularity, which is a key to successful programming. FP creates a natural framework for developing small and simple modules which are then glued together.

IBM DeveloperWorks also published an article a couple of years ago showing how to do FP in Java, and Joel Spolsky of 'Joel on Software' has lamented the fact that all-Java universities these days are not preparing programmers by teaching them a functional language "Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming."

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

FunctionalJ by Michael Neale

functionalj.sourceforge.net/ is worth checking out for those interested.

If you statically import its helper class, you can have things like map(), filter() etc etc...

Functional Programming by Billy Newport

should be taught to everyone as should logic based programming. One of the best books on this stuff is "Structure and Interpretation of Programming Languages" by Abelson and Sussman. You can't know enough techniques.

wallflower by Joost de Vries

What's up with functional programming forever sitting at the edge of the party moping about being superior while the other languages are having all the fun.

I'm wary of supposedly superior technologies that never make it.

Has anybody made an information system using FP? I'm really curious what that would look like. It seems to me information systems are all about side effects.

Oh, and if you want to FP on JVM look into the Martin Odersky's language Scala.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

3 Discuss
BT