How This Book Is Organized

We’ll start with an introduction to patterns and how they relate to functional programming. Then we’ll take a look at an extended example, a small web framework called TinyWeb. We’ll first show TinyWeb written using classic object-oriented patterns in Java. We’ll then rewrite it, piece by piece, to a hybrid style that is object oriented and functional, using Scala. We’ll then write in a functional style using Clojure.

The TinyWeb extended example serves a few purposes. It will let us see how several of the patterns we cover in this book fit together in a comprehensive manner. We also use it to introduce the basics of Scala and Clojure. Finally, since we’ll transform TinyWeb from Java to Scala and Clojure bit by bit, it gives us a chance to explore how to easily integrate Java code with Scala and Clojure.

The remainder of the book is organized into two sections. The first, Chapter 3, Replacing Object-Oriented Patterns, describes functional replacements for object-oriented patterns. These take weighty object-oriented patterns and replace them with concise functional solutions.

Peter Norvig, author of the classic Lisp text Paradigms of Artificial Intelligence Programming: Case Studies in Common Lisp [Nor92], current director of research at Google, and all-around very smart guy, pointed out in Design Patterns in Dynamic Languages that expressive languages like Lisp could turn classic object-oriented patterns invisible.[1]

Unfortunately, not many people in the mainstream software development world seem to have read Norvig, but when we can replace a complicated pattern with something simpler, it makes sense that we should. It makes our code more concise, easier to understand, and easier to maintain.

The second section, Chapter 4, Functional Patterns, describes patterns that are native to the functional world. These patterns run the gamut from tiny—patterns consisting of a line or two of code—to very large—ones that deal with entire programs.

Sometimes these patterns have first-class language support, which means that someone else has done the hard work of implementing them for us. Even when they don’t, we can often use an extremely powerful pattern, Pattern 21, Domain-Specific Language, to add it. This means that functional patterns are more lightweight than object-oriented patterns. You still need to understand the pattern before you can use it, but the implementation becomes as simple as a few lines of code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.214