I have a soft spot in my heart for Perl. It was the first language that I made any serious use of as a professional software developer. I’ve learned a lot from Perl and about Perl, and I know that the language has a reputation for being ugly. So how does a developer transform an “ugly” language into something special and possibly even “pretty?”
In the Perl community, the proposed question might be met with reactions of “TIMTOWTDI!” (pronounced “Tim Toady” and representing the very long acronym of “There is more than one way to do it!”) After all, they might say, what is “pretty” code? To me, pretty code is code that is maintainable, robust, and fast, probably in that order of preference. I think that there exists a book about Perl that illustrates how to write pretty code (per my definition) and here are my thoughts about it:
Last week I finished reading a book written by a well respected individual in the Perl community. Like Douglas Crockford with the JavaScript language (whom I mentioned in my previous post), this author is someone who has had a presence in Perl and really knows his stuff because of years of experience.
The book is Perl Best Practices and the author is Damian Conway. Unlike Crockford’s JavaScript: The Good Parts, Conway’s book is much larger and spans more than three times the number of pages of Crockford’s 153 page book. Damian uses that space quite effectively and provides some great insight into how to write better Perl code.
Perl Best Practices is not a book for fledgling Perl developers. If you’re learning Perl syntax for the first time, look elsewhere (e.g., Programming Perl or Perl in a Nutshell), however, be sure to come back quickly to this book!
The real strength I see in Perl Best Practices is the overarching guidance about how to craft Perl code into something maintainable by people. For code to be effective, it cannot exist in a vacuum. The best code is used and read and maintained by many people. Conway’s book explains some critical concepts to write rich code, but he writes it in a way that emphasizes how to make the code safe in the future and update-able to others. After reading Perl Best Practices, I feel better equipped to write Perl code that other developers would value. I would love for those hypothetical developers to look at my future work and say “Oooo… that’s pretty!”