Perl Best Practices

Perl Best Practices

3.6 3
by Damian Conway

View All Available Formats & Editions

Many programmers code by instinct, relying on convenient habits or a "style" they picked up early on. They aren't conscious of all the choices they make, like how they format their source, the names they use for variables, or the kinds of loops they use. They're focused entirely on problems they're solving, solutions they're creating, and algorithms they're

…  See more details below


Many programmers code by instinct, relying on convenient habits or a "style" they picked up early on. They aren't conscious of all the choices they make, like how they format their source, the names they use for variables, or the kinds of loops they use. They're focused entirely on problems they're solving, solutions they're creating, and algorithms they're implementing. So they write code in the way that seems natural, that happens intuitively, and that feels good.

But if you're serious about your profession, intuition isn't enough. Perl Best Practices author Damian Conway explains that rules, conventions, standards, and practices not only help programmers communicate and coordinate with one another, they also provide a reliable framework for thinking about problems, and a common language for expressing solutions. This is especially critical in Perl, because the language is designed to offer many ways to accomplish the same task, and consequently it supports many incompatible dialects.

With a good dose of Aussie humor, Dr. Conway (familiar to many in the Perl community) offers 256 guidelines on the art of coding to help you write better Perl code—in fact, the best Perl code you possibly can. The guidelines cover code layout, naming conventions, choice of data and control structures, program decomposition, interface design and implementation, modularity, object orientation, error handling, testing, and debugging.

They're designed to work together to produce code that is clear, robust, efficient, maintainable, and concise, but Dr. Conway doesn't pretend that this is the one true universal and unequivocal set of best practices. Instead, Perl Best Practices offers coherent and widely applicable suggestions based on real-world experience of how code is actually written, rather than on someone's ivory-tower theories on howsoftware ought to be created.

Most of all, Perl Best Practices offers guidelines that actually work, and that many developers around the world are already using. Much like Perl itself, these guidelines are about helping you to get your job done, without getting in the way.

Praise for Perl Best Practices from Perl community members:

"As a manager of a large Perl project, I'd ensure that every member of my team has a copy of Perl Best Practices on their desk, and use it as the basis for an in-house style guide."— Randal Schwartz

"There are no more excuses for writing bad Perl programs. All levels of Perl programmer will be more productive after reading this book."— Peter Scott

"Perl Best Practices will be the next big important book in the evolution of Perl. The ideas and practices Damian lays down will help bring Perl out from under the embarrassing heading of "scripting languages". Many of us have known Perl is a real programming language, worthy of all the tasks normally delegated to Java and C++. With Perl Best Practices, Damian shows specifically how and why, so everyone else can see, too."— Andy Lester

"Damian's done what many thought impossible: show how to build large, maintainable Perl applications, while still letting Perl be the powerful, expressive language that programmers have loved for years."— Bill Odom

"Finally, a means to bring lasting order to the process and product of real Perl development teams."— Andrew Sundstrom

"Perl Best Practices provides a valuable education in how to write robust, maintainable Perl, and is a definitive citation source when coaching other programmers."— Bennett Todd"I've been teaching Perl for years, and find the same question keeps being asked: Where can I find a reference for writing reusable, maintainable Perl code? Finally I have a decent answer."— Paul Fenwick"At last a well researched, well thought-out, comprehensive guide to Perl style. Instead of each of us developing our own, we can learn good practices from one of Perl's most prolific and experienced authors. I recommend this book to anyone who prefers getting on with the job rather than going back and fixing errors caused by syntax and poor style issues."— Jacinta Richardson"If you care about programming in any language read this book. Even if you don't intend to follow all of the practices, thinking through your style will improve it."— Steven Lembark"The Perl community's best author is back with another outstanding book. There has never been a comprehensive reference on high quality Perl coding and style until Perl Best Practices. This book fills a large gap in every Perl bookshelf."— Uri Guttman

Read More

Product Details

O'Reilly Media, Incorporated
Publication date:
Sales rank:
Product dimensions:
7.00(w) x 9.19(h) x 0.98(d)

Customer Reviews

Average Review:

Write a Review

and post it to your social network


Most Helpful Customer Reviews

See all customer reviews >

Perl Best Practices 3.7 out of 5 based on 0 ratings. 3 reviews.
Anonymous More than 1 year ago
Anonymous More than 1 year ago
Guest More than 1 year ago
It's almost a certainty that you won't like all of the suggestions that follow if you're an experienced developer. Author Damian Conway has done an outstanding job of designing a book to help you write better Perl code. Conway begins by explaining why it might be worth reassessing your current coding practices. Next, the author tackles the many contentious issues of code layout. Then, he presents a series of guidelines that can help you choose more descriptive name for variables, subroutines, and namespaces. Conway continues by providing a simple set of rules that can help you avoid common pitfalls when creating character strings, numbers, and lists. In addition, the author next explores a robust approach to using variables. He also examines Perl's rich variety of control structures, encouraging the use of those that are easier to maintain, less error-prone, or more efficient. The author next suggests a series of techniques that can make documenting your code less tedious, and therefore more likely. Next, the author discusses better ways of using some of Perl's most popular built-in functions, including sort, reveres, scalar, eval, unpack, split, substr, values, select, sleep, map and grep. Conway continues by describing efficient and maintainable ways to write subroutines in Perl, including the use of positional, named, and optional arguments argument validation and defaults safe calling and return conventions predictable return values in various contexts and, why subroutine prototypes and implicit returns should be avoided. Next, he explains how to open and close files reliably when to use line-based input, how to correctly detect interactive applications the importance of prompting and, how best to provide feedback to users during long non-interactive tasks. Then, he offers advice on demystifying Perl's many dereferencing syn-taxes discusses why symbolic references create more problems than they solve and, recommends ways to prevent cyclic reference chains from causing memory leaks. The author next presents guidelines for using regular expressions. Then, he advocates a coherent exception-based approach to error handling, and explains why exceptions are preferable to special return values or flags. Next, he addresses the design and implementation of command-line interfaces, both for individual programs and for application suites. Conway continues by offering a robust and efficient approach to creating objects and class hierarchies in Perl. Next, he looks at non-object-oriented modules exploring the best ways to create them design their interfaces declare and check their version numbers and, refacter existing code into them. Then, he encourages the use of testing, advocating test-driven design and development using the core Test:: modules. Finally, he offers several additional guidelines on miscellaneous topics such as revision control interfacing to code written in other languages processing configuration files text formatting tied variables benchmarking and profiling your code caching techniques and, some general advice on refactoring. With the preceding in mind, the author has done an excellent job of designing a book that produces Perl code that is clear, robust, efficient, maintainable, and concise. At the end of the day, the guidelines in this book, much like Perl itself, are about helping you get your job done, without getting in the way.