Modern Perl 4th edition, a review
The 4th edition of Modern Perl by chromatic is out. I was given an advance copy to review and the book features my praise quote, so I figured it was about time I wrote my notes up into a longer review. Overall I really like the changes to the new edition; in my opinion, Modern Perl continues to provide a valuable introduction to idiomatic Perl programming.
Learn the idiomatic Perl style
Modern Perl isn’t like your typical dry programming book. For one thing, it’s opinionated. Author chromatic draws on his experience to provide an insiders’ guide that shows the right way to program in Perl.
The text is fast-moving and doesn’t baby the reader. Instead of “hello World”, the book begins by teaching the reader how to use
perldoc and draw upon the official documentation when they get stuck. Don’t waste time with Google when the answer can be found in seconds at the command line.
Chapters 1 and 2 introduce the Perl philosophy and Community. The book rapidly covers the major features of Perl (chapters 3 - 7) and even more advanced topics like recursion, anonymous functions and closures. Peppered throughout are gems of wisdom explaining the rationale behind a given concept. For instance, on including parentheses on all function calls (even ones without arguments):
While these parentheses are not strictly necessary for these examples—even with strict enabled—they provide clarity to human readers as well as Perl’s parser. When in doubt, use them.
Modern Perl 4th edition, Chapter 5, Declaring Functions
The focus here, though is on the practical and chromatic quickly moves on to advising on elements of good Perl style and how to learn it (chapter 8) and real-World programming tips (chapter 9). This is an honest, expert’s account of Perl, and chapter 11 describes what to avoid in Perl (chapter 5 also has an entry on function misfeatures).
Whilst this is an introductory text, chromatic does find time to touch upon several intermediate concepts like taint, schwartzian transforms and tail call optimizations. There is something for everybody: re-reading the section State-versus-Closures (chapter 5) I learned a nuance that I hadn’t appreciated before.
Modern Perl does assume a lot and this could make it challenging for complete novices. For example the code snippets assume the reader can distinguish between command line and Perl programming context. Map and grep are used in examples but are not covered in the language overview chapters. But these are minor nits.
About 10 years ago, Perl enjoyed something of a renaissance called “Modern Perl”. This was a movement that developed powerful new libraries, tools and applications which invigorated Perl programming and gave it a new lease-of-life. Today the phrase is almost synonymous with Perl “best practices” and its ethos continues to help Perl flourish.
The 4th edition brings a lot of changes, but it’s a case of evolution, not revolution. New Perl features like the double-diamond operator (
<<>>) and subroutine signatures are covered. Almost every paragraph has been updated), but the chapter structure remains the same and many of the edits are tweaks rather than wholesale re-writes. Many of the changes improve the readability of the text, others de-jargonize it, like this:
Functions are a prime mechanism for abstraction, encapsulation, and re-use in Perl.
Modern Perl, 3rd Edition, Chapter 5
Functions are a prime mechanism for organizing code into similar groups, identifying individual pieces by name, and providing reusable units of behavior.
Modern Perl, 3rd Edition, Chapter 5
Which is clearly easier for beginners to understand. Code-wise, many of the examples have changed from a BSD to K&R style, presumably to save vertical space. Overall the book length remains about the same (205 vs 204 pages).
The biggest change with the new edition comes from The Pragmatic Bookshelf - their version is simply gorgeous. Full color with larger fonts, icons and callouts, the book really pops. This is the layout Modern Perl needs and deserves. See this comparison between the Onyx Neon and Pragmatic Bookshelf versions:
As an opinionated introduction to Perl, Modern Perl is a compromise between a tutorial and a best-practices style cookbook. I love the direction and terse writing style, but the book might move too fast for complete beginners. So it depends on what you’re looking for - Beginning Perl and Learning Perl are fine introductions to the language. Effective Perl Programming is my favorite Perl cookbook. But Modern Perl is a unique blend of both styles.
Where to get it
You can read Modern Perl online for free, and there are downloadable versions available from Onyx Neon. If you want it as an ebook, I would recommend the Pragmatic Bookshelf version - it’s beautifully styled, free, and you’ll be eligible for updates to the text as/when they appear.