Book Review: Perl Best Practices
We all have done it, haven't we? We've looked at source code--either our own or someone else's--and asked that age-old programming question: "What is this code doing?". When code is written in Perl, the aforementioned question probably is uttered more than it needs to be, as Perl--the ever-popular duct tape of the Internet--often is used to produce code that is hard to understand. This problem is exasperated by the Perl community's near obsession with letting programmers work in whatever way suits them. Although the Perl motto, "There's more than one way to do it", often can be a strength, it also can work against large projects and team efforts. This may be especially true if every team member's code is a law-unto-itself when it comes to style, coding standards, layout and idioms used. Typically, if this is the case, you end up with a Perl code base that is unmaintainable.
In tackling this problem head-on, Damian Conway is nothing if not brave. In his latest book, Perl Best Practices, Damian attacks subjects that should be close to the heart of every Perl programmer: coding standards, styles and development practices and behaviors. In 500 pages or so, Conway presents what he believes to be a consistent set of standards and styles for developing maintainable code when using Perl. Almost magically, there are 256 of these guidelines in the book, offering help to Perl programmers of every ability.
Conway's bravery comes from his decision to highlight the problems that programmers can get themselves into when programming in Perl. Typically, these problems are with Perl as opposed to the programmer, and there's plenty of criticism of the programming language adored by the majority of Conway's readership. Conway's saving grace is that, having criticized, he then proceeds to demonstrate a technique or practice for avoiding that which he criticized. Make no mistake, some of Conway's advice is controversial. Indeed, the outright banning of unless is highlighted by Conway himself as potentially raising a few eyebrows. And, there's plenty of other guidelines that will produce gasps and grunts from many a Perl programmer. As an example, consider the "Don't use bareword filehandles" guideline from the start of Chapter 10, which warns against writing code such as this:
open FILE, '<', $filename
or croak "Can't open '$filename': $OS_ERROR";
If you are reading this and wondering what's wrong with the above code, don't despair. On the surface, nothing is too wrong with the code, as it does indeed open a file and assign it to a filehandle. What can happen, though, is this innocent-looking code can lead to problems when systems grow to anything larger than a 20-line throw-away script. It is more robust, reliable, efficient and maintainable to rewrite the above code using an indirect filehandle, like so:
open my $FILE, '<', $filename
or croak "Can't open '$filename': $OS_ERROR";
Why it is important to do this is covered in detail by Conway. After reading his reasoning, it is hard to argue against or ignore what's being advised, even though every other Perl book I've ever seen--including mine--open files using a bareword filehandle. Of course, it is at times such as this that Conway's advice and explanations become invaluable. By describing the awfulness that can result from not adhering to the guidelines and then following up with a robust solution, many a late-night or multi-day debugging session can be avoided. Programmer sanity is, without a doubt, something to strive for and maintain. It is clear that one of Conway's main goals in writing this book is to keep you and others that read your code sane by steering the programmer away from many of Perl's pitfalls.
While working through the book, I learned a lot about the current problems with Perl 5. I found myself constantly reciting the same prayer, "Oh my, please let them fix that in Perl 6." All indications within Perl Best Practices say that these things will be fixed. However, as Perl 5 will be around for quite some time, Conway's book has real value now that will only increase as time goes by. Even when Perl 6 does arrive, the majority of the guidelines will remain valid and should continue to be followed.
Of interest is the long list of technical reviewers thanked at the start of the book: it includes some of the biggest names in the Perl world. So Perl Best Practices is not simply Conway's best practices, but the best practices actually practiced by the inner circle that Conway identifies.
One small gripe is I wish the guidelines had been numbered, for ease of reference. Nice touches include the decision to highlight "good code" in bold mono throughout the text and "bad code" in regular mono. The book also provides plenty of references to supporting material on the Web. The jokes, when they come, often are something special.
As all Perl programmers know, there's an awful lot to Perl, and there's an awful lot of Perl to learn. In addition to covering the essential material, Conway's book discusses some of the darker recesses (features?) of Perl that I've never seen covered anywhere else. By working through Perl Best Practices, you will become a better Perl programmer, even if you decide not to adopt the guidelines offered to you. From my own point of view, I'd like to see a CPAN icon that indicates whether a submitted module conforms to Conway's 256 guidelines. I'd like to build my future applications using shared modules that I know I'll be comfortable reading, amending and working with.
For now, I'm off to update my Perl Tutorial to conform to Conway's guidelines. I'm also looking forward to the first official release of Perl 6. Damian Conway's Perl Best Practices is a must-have.
Paul Barry lectures at the Institute of Technology, Carlow, in Ireland. He is the author of two textbooks that use Perl. He can be contacted at paul.barry@itcarlow.ie.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- RSS Feeds
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- Developer Poll
- Dart: a New Web Programming Experience
- What's the tweeting protocol?
- May 2013 Issue of Linux Journal: Raspberry Pi
- Reply to comment | Linux Journal
1 hour 38 min ago - Reply to comment | Linux Journal
2 hours 25 min ago - Web Hosting IQ
3 hours 59 min ago - Thanks for taking the time to
5 hours 36 min ago - Linux is good
7 hours 33 min ago - Reply to comment | Linux Journal
7 hours 51 min ago - Web Hosting IQ
8 hours 21 min ago - Web Hosting IQ
8 hours 21 min ago - Web Hosting IQ
8 hours 22 min ago - Reply to comment | Linux Journal
11 hours 23 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.



Comments
0www
thanks bro nice article Paul Barry
"i hate micr0z0rt :D"
Nice book
Nice book :)
search
nice book
A must-read for any Perl programmer
Covering the sections other Perl books do not cover..
Great Help.....
Thanks
Good and Informative
Nice work.. Good and Informative book ..
Useful resource
I found the book to be an interesting read, and certainly worth a look. While in The Real World I'm still guilty of ignoring some of these best practices, reading this has certainly improved the quality of my code.
?
Is this journal hosted by wordpress?
Comment
Interesting article
Very good book
This is the book that tells you how to do things until you gain enough experience to know how to do them. Then you'll do them as described in this book because the way described is so good.