Shiny New Perl – Modern Perl!

I wrote a post last week talking about how outdated a lot of Perl seems to be, and the comments were full of people discussing it.  One of the things mentioned repeatedly was chromatic‘s new book Modern Perl.  I had seen several of the posts where he discussed the book on his blog and knew it was coming, but it was news to me that it was released

Not only is it released, but chromatic has graciously made the book available  for download as PDF.  His publisher has it as both letter-sized and A4 sized formats for print.  It’s released under one of the Creative Commons (by-nc-nd) licenses so you can use it, share it, and distribute it freely and widely.  The blog announcement mentioned above encourages you to do so.

I’ve taken the time to give the book a first read, and I can only say that I’m impressed.  According to the blog posts, the book was produced in POD which was stored in a public Git repository for constant feedback and refinement from members of the community.  That’s really slick, and the content of the book shows how much work went into it.

The book does some things differently than other Perl books I’ve read, and I approve.  The preface starts of by giving the requirements for running the sample code from the book.  That includes Perl of no later than 5.10.1, and “use strict” and “use warnings”.  There is no example of trying to write code that works in Perl 5.6 or is just like the other things you’ve seen before .

It begins with some interesting sections discussing the philosophy of Perl, and where the community lives and how to find them.  It explains perldoc and, and leaves it to the reader to use those as references.  These are key items often overlooked in books, and rightly deserve a place at the front of the book.

There are several chapters about Perl, the language.  These chapters cover almost all of the language.  They cover it at some depth, pausing to explain how it works and to shine a flashlight into the dark corners and point out all the odd bits you can trip over.  These chapters manage to be easily readable and to avoid most of the technical jargon they don’t need.  When a technical term is needed, it is introduced, explained and then used properly.

The book includes the best description of arity and fixity I’ve ever seen.  I’d gathered the concepts, but didn’t know the names.   I knew the names of the different kinds of operators – infix, prefix, circumfix, and postcircumfix, but have never seen them described so well.  Similarly, this is the clearest and most concise description I’ve ever read of closures, including what they are, why they work, why they’re called “closures” and why they’re interesting.

In addition, the book has the best explanation of why it is important to handle different character sets properly that I have ever seen.  It demonstrates some of the common pitfalls and shows how simple it is to accidentally produce strings which will be unreadable in any format because they’ve got data from two different character sets.  For anyone who isn’t paying attention to Unicode yet, this should be a mandatory read.

There are two chapters on object oriented Perl.  The book starts with Moose and shows its use and how to use it.  Only then does it show the built-in Perl OO constructs.  They’re a lot easier to explain once you’ve seen how objects should work, so you might have a grasp of why you’d be writing a “new” function.  They are well done chapters.

Then come what I considered the important parts!  There are chapters on how to write maintainable code, and what that means.  A chapter discusses some of the common idioms seen on the Internet and on CPAN.  There is a chapter including testing, warnings, and distributions.  There’s a chapter that goes “beyond syntax” to cover why things are done and how to do them well and explains a couple of the common methods used, such as the Schwartzian Transform.  Finally, there is a “things to avoid” chapter and some things chromatic feels are missing from Perl.

I think all of these things are useful and important, and didn’t see anything in the book I strongly disagree with.  I read things I didn’t know, ranging from silly little features (you can us ++ on a string!) to the names of some of the computer science concepts I’d never heard well explained before.  The coverage of the language and how it works is excellent, and reading this will help people go from fumbling with it, to really understanding how it works and why it does the things it does.

My biggest complaint about the book is that I wish there were more of the discussion about writing good Perl.  One of the common complaints about Perl is that it’s ugly, and unmaintainable.  It doesn’t have to be, and there are a lot of techniques to make it better.  I’d have loved to see more discussion of that in this book.  (I realize I have no one to blame but myself, as this book was produced with the collaboration of many and I could have been involved.)

I also just noticed a language feature it missed discussing – formats.  They are another dark corner, but I’m surprised they aren’t there.  Maybe I missed them, but neither a search nor the index shows them.

As you can see, I don’t have much to complain about here, and I’m going to be sending this book around on the internal Perl mailing lists at work.  I feel it’s an excellent place for an intermediate Perl programmer to go to get a really firm grasp on the language and will be an unbeatable way to help many of the self-taught engineers who write Perl to solidify and put names to the concepts they’ve been working with but may not have had such a clear grasp of.

At this point, I’d consider this a more valuable book than “Programming Perl” since it contains so much information about the language that isn’t just in the perldoc.  It’s also less idiosyncratic and contains many fewer in-jokes.  It’s a much more useful and professional book, and I recommend it.

Yeah, you could say that I liked it.

Thank you, chormatic, for the time, work, and effort to produce this!

Tags: , ,

4 Responses to “Shiny New Perl – Modern Perl!”

  1. Dave Rolsky says:

    I suspect he left out formats because they fall into the “things you shouldn’t use” category. Perl’s format feature is just weird as heck.

    The Text::Reform module on CPAN is a much better choice. The API is reasonably sane, and it provides more features than Perl’s built-in formats.

  2. Jeremy Leader says:

    Minor nit: you say “Perl of no later than 5.10.1″, I think you mean “Perl no older than 5.10.0″!

Leave a Reply