xvii
Introduction
is book is the culmination of many brash years and hard lessons. e story starts all the way back when
I migrated from C++ into perl. e perl programming language was amazingly powerful compared to the
low-level manipulations and bookkeeping of C++. (e fact that it was “slow” never bothered me – I would
rather write powerful, eective slow code than weak, buggy fast code.) In the world of perl, there was the idea of
an “anonymous subroutine” that could be passed around and manipulated. You could also directly manipulate
the symbol table. e symbol table is the collection of function names available to the program. Between these
two things, I realized that I could code at a higher level: I could write subroutines that returned subroutines and
store those into the symbol table, eectively having my code write code at runtime. In perl, these subroutine
factories are called “template functions.” I proceeded to write some truly unreadable – but truly powerful – perl.
I shared this revelation with my friend and mentor, Brian Hurt. He was the grizzled veteran developer who
seemed to have seen it all. Brian told me that what I was doing was this thing called “functional programming,”
and encouraged me to look into proper functional languages, specically OCaml, and its derivative, JoCaml.
I was immediately hooked. By 2008, I presented “Why Rubyists Should Learn OCaml” to the Ruby Users
Group of Minnesota (Ruby.MN).
1
ere was a power in functional programming that was truly incredible
compared to the then-standard way of writing code. Moreover, my mathematical background played very
nicely with functional programming: the fact that state did not change meant that I could employ the same
kind of reasoning to my programs that I employed with mathematical equations. I presumed at the time that a
functional programming language would rise and fundamentally transform what it means to program, much
as Java ascended and made Object Oriented Programming ubiquitous. So far, this hasn’t happened.
e next chapter came with the rise of the Groovy programming language. Groovy’s MetaClass
functionality provided a way for me to perform the same tricks as in perl, but in a way that leveraged all that
existing Java code. is was having my cake and eating it, too. All that open source software that existed
for Java, and all that technical expertise that had been built up on the JVM could nally mix with these
“functional stunts.” It wasn’t functional programming – and I got in quite a bit of trouble on the Internet for
saying as much – but it was certainly borrowing some powerful tricks from functional programming. We get
into what was happening in chapter 1.
When Java 7 rolled out, it introduced the invokedynamic keyword (which we cover in chapter 8). e
keyword was touted as being support for dynamic languages, but I recognized it for what it was: JVM support
for those same functional stunts. ere was no longer any technical reason why you could not perform the
same functional stunts in Java itself. e Java language’s syntax, however, simply could not keep up with its
underlying implementation. We had to wait until Java 8. With Java 8, we nally got lambdas into the Java
language itself, along with basic support for some of the most powerful functional stunts.
is is a truly exciting language change. I think it is as transformative to the Java language as the
introduction of object oriented programming in the rst place, and it shows that the functional stunts, which
were esoteric yet impressive back in perl, are truly primed to become industry standard practices. at is
why this book is so critical: it is no exaggeration to say that learning the content in this book will help you
program throughout the remainder of your career. Sooner or later, you are going to have to learn to harness
the power of lambdas. Might as well start now.
1
http://www.youtube.com/watch?v=2T5syww4Nn4.
www.it-ebooks.info