Book Review: Higher Order Perl

Mark Jason Dominus has written a book that reminds the reader that no matter how foreign and weird we may think the other camp is (and rest assured, they probably think the same of us), we can learn an awful lot by practicing thinking the way they do.


June 01, 2005
URL:http://www.drdobbs.com/web-development/book-review-higher-order-perl/184416213

Ken Williams [email protected] is a Research Scientist at Thomson Legal and Regulatory in St. Paul, MN. He is the primary author of several CPAN modules, including Module::Build, Path::Class, Apache::Filter, and AI::Categorizer.


Five years is a long time to spend writing a computer book. If we are to believe the tired old adage that computing technology advances at the rate of doubling every 18 months, then about 90 percent of our present technical world wasn't around five years ago. In other words, when Mark Jason Dominus started writing Higher Order Perl, perhaps only 10 percent of his subject matter actually existed yet. Maybe this means we shouldn't believe the adage, or more likely, that it just doesn't apply very well to the writing of a book on Perl programming, but still—five years is a long time to spend writing a computer book.

If you want to tilt the odds a bit better in your favor, you can choose a topic that's already been kicking around a while and isn't likely to change much over five years. A topic like the basic principles of Lisp programming.

This, oddly enough, is what Dominus has done: written a book on how the basic principles of Lisp programming can be applied in Perl programming. And the result isn't just good, it's absolutely excellent. His book reminds the reader, or at least this reader, that no matter how foreign and weird we may think the other camp is (and rest assured, they probably think the same of us), we can learn an awful lot by practicing thinking the way they do.

Functional Programming

Dominus's aim in Higher Order Perl is to show Perl programmers some of the techniques that are commonplace in Functional Programming. Functional Programming, exemplified in languages like Lisp, ML, and Haskell, is essentially a different philosophy of programming than we see in Imperative Programming languages like C or Pascal. In Imperative Programming, you think of a program as a sequence of commands; you tell the computer, "do this, then do this, then do this." The computer then performs the actions specified, and typically shows you the side effects (e.g., the output of print statements) of doing so.

By contrast, in pure Functional Programming, a program consists entirely of functions; you tell the computer, "here's how you do this, and here's how you do this, and here's how you do this other thing." Each function is built from other functions, and may even take functions as arguments and/or produce functions as output. The computer then evaluates some function that's been designated as the main function, and shows you its return value.

It's most useful to think of Functional vs. Imperative programming as a distinction in philosophies rather than as a strict categorization of programming languages. Just as any individual person may embody more than one philosophy of life, any individual language may enable more than one philosophy of programming. In fact, Lisp itself is not even considered a pure functional language, even though it certainly encourages its practitioners to use many Functional Programming techniques.

We as Perl programmers know that Perl is a postmodern mish-mash of many different languages that have, at one time or another, caught the fancy of Larry Wall and the rest of the Perl Porters. Clearly some pieces of the language, such as for loops, variable scoping, and assignment syntax, come more or less directly from languages like C. Our beloved regular expressions come from (and render pretty much obsolete) awk and sed. Our object-oriented mechanisms ultimately come from Smalltalk. The Lisp-ish elements, like dynamic typing of variables, runtime manufacturing of functions, and variations on Perl's map concept, are the chief concerns of Higher Order Perl.

Strengths and Weaknesses

The strengths of Higher Order Perl far outweigh the weaknesses:

That said, Higher Order Perl isn't without weaknesses:

All told, Higher Order Perl is a tremendous book, and confirms the notion that Perl is All Grown Up. It can do tricks that most other languages can only dream about, and Mark Jason Dominus is eager to show us how.

TPJ

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.