Book Review: Higher-Order Perlby Reinhard Voglmaier
Perl is considered by many people as a scripting language', intended as a way to quickly write handy little scripts. However, it is also well suited for creating robust applications with object-oriented programming. The book Higher-Order Perl shows both of these approaches — creating extensible programs (not just scripts) using object-oriented features as well as functional or declarative programming techniques.
The book provides not only practice but also a lot of programming theory that you'll appreciate when writing applications. In spite of the theoretical background that the author provides, I don't consider this to be an academic book.
According to the author's Web site, "Higher-Order Perl is about functional programming techniques in Perl. It's about how to write functions that can modify and manufacture other functions. Why would you want to do that? Because that way your code is more flexible and more reusable. Instead of writing ten similar functions, you write a general pattern or framework that can generate the functions you want; then you generate just the functions you need according to the pattern. The program doesn't need to know in advance which functions are necessary; it can generate them as needed. Instead of writing the complete program yourself, you get the computer to write it for you."
The book first explains recursive problem solving and the fundamentals of callbacks. Callbacks are also discussed in the second chapter on dispatch tables and recursion. The chapters build on each other so it is wise to read the chapters in order, rather than to jump back and forth.
The third chapter explains caching in detail using the "memoization" written by the author. Many people think Perl does not know about iterators, but the fourth chapter shows the theory and some useful examples. The following chapter shows how to convert recursive functions into iterators. After a chapter about infinite streams, the author presents the concept of currying and higher-order functions.
The chapter of parsing alone is worth the price of this book. I do not know a better text about parsing in Perl. The book concludes with a chapter about declarative programming, another highlight in this book.
Should you buy it?
Yes. Higher-Order Perl is one of the Perl books that should have a place on the bookshelf of every Perl programmer. It offers an in-depth understanding of important programming techniques and fundamental concepts. It contains a many useful examples available from the author's Web page, the same site where the author promises to publish the whole book.