Sebastopol, CA--Not all approaches to coding are equal. No matter how fervently one might espouse the Perl credo, there are still rules, conventions, and practices that help programmers communicate and coordinate with one another. "They provide a uniform and predictable framework for thinking about problems, and a common language for expressing solutions," writes Damian Conway in his latest book, Perl Best Practices (O'Reilly, US $39.95), a collection of guidelines to help programmers produce the best code possible. "Code matters," he says. "So the way in which you code matters too."
Every programmer has a unique approach to writing software--a unique coding style. "Programmers' styles are based on their earliest experiences in programming--the linguistic idiosyncrasies of their first languages, the way in which code was presented in their initial textbooks, and the stylistic prejudices of their early instructors," Conway explains. "That style will develop and change as the programmer's experience and skills increase. Indeed, most programmers' style is really just a collection of coding habits that have evolved in response to the opportunities and pressures they have experienced throughout their careers."
Conway further observes that just as in natural evolution, those opportunities and pressures may lead to a coding style that is fit, strong, and well adapted to the programmer's needs. "Or it may lead to a coding style that is nasty, brutish, and underthought. But what it most often leads to is something even worse: Intuitive Programmer Syndrome."
According to Conway, many programmers code by instinct. "They aren't conscious of the hundreds of choices they make every time they code: how they format their source, the names they use for variables, the kinds of loops they use," and so on. The Intuitive Programmer writes code in a way that feels natural, happens intuitively, and feels good, but doesn't necessarily result in the best code possible.
In Perl Best Practices, Conway sets forth 256 guidelines that are designed to help programmers produce code that is clear, robust, efficient, maintainable, and concise. There are many ways of measuring code quality, and Conway doesn’t profess that his is the only approach. Instead, he offers a set of best practices that is "coherent, widely applicable, balanced in its aims, and is based on real-world experience of how code is actually written, rather than on someone's ivory tower theories on how code ought to be created."
The guidelines in Perl Best Practices 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. Above all, it's a set of practices that actually works, and that many developers around the world are using already. Much like Perl itself, the guidelines are about helping programmers get their jobs done, without getting in the way.
Conway doesn't expect experienced Perl developers to like all the suggestions in his book. They'll find some of them unnatural or counterintuitive, while others will feel excessively rigid and un-Perlish. Or, perhaps they'll just seem unnecessarily different from long-ingrained coding habits. He urges programmers to set those feelings aside as they read, and review the advice in the book as they would any other proposed code enhancement. "Just thinking about these issues--becoming conscious of the way you currently write code--can be of enormous benefit even if you don't adopt a single one of the recommendations."
Early praise for Perl Best Practices:
"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 trainer and author
"Perl Best Practices has just saved me untold hours. I can simply write 'Department Coding Standards' on the front in big black marker."
--Andy Lester, Web Applications Manager, Follett Library Resources
"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, Perl Foundation Steering Committee Chairman
"This isn't just a dead-tree perldoc perlstyle, it's a Damianized style guide, introduction to built-ins, structural discussion, and much more. True to usual form, Damian Conway uses humor, excellent examples, and deviousness to tell me why I should apply these best practices in my development. I was amazed at the number of simple utilities and tricks in this book to help me become a better developer...Even if you really are smart enough to know everything in this book, it is an entertaining read, and how often do you really get to enjoy reading a technical book? I can tell it will be a great re-read, cover-to-cover."
--Jason Hall, "The Perl Review"
Additional Resources:
- Chapter 9, "Subroutines"
- More information about the book, including table of contents, index, author bio, and samples
- A cover graphic in JPEG format
Perl Best Practices
Damian Conway
ISBN: 0-596-00173-8, 281 pages, $39.95 US, $55.95 CA
order@oreilly.com
1-800-998-9938; 1-707-827-7000About O’Reilly
O’Reilly Media spreads the knowledge of innovators through its books, online services, magazines, and conferences. Since 1978, O’Reilly Media has been a chronicler and catalyst of cutting-edge development, homing in on the technology trends that really matter and spurring their adoption by amplifying “faint signals” from the alpha geeks who are creating the future. An active participant in the technology community, the company has a long history of advocacy, meme-making, and evangelism.