Perl Best Practices

Perl Best Practices
by Damian Conway

Perl Best Practices
List Price: $39.99
Our Price: $21.30
You Save: $18.69 (47%)
Availability: Usually ships in 1-2 business days
Buy Used: from $13.00 (click here)
Category: Book
See more book details and other editions


or

Book Summary Information

Author: Damian Conway
Edition: Paperback
Audio: English (Unknown); English (Original Language); English (Published)
Published: 2005-07-19
ISBN: 0596001738
Number of pages: 544
Publisher: O'Reilly Media
Product features:
  • ISBN13: 9780596001735
  • Condition: New
  • Notes: BRAND NEW FROM PUBLISHER! 100% Satisfaction Guarantee. Tracking provided on most orders. Buy with Confidence! Millions of books sold!

Book Reviews of Perl Best Practices

Book Review: Programming Perl well (and fighting Enthropy from day 1)
Summary: 5 Stars

There is a problem that has troubled some of us (perhaps the ones, like me, coming from static languages) with Perl. On one side, we discover the inmense power of the language, that allows to do things not even conceivable before. However, we also discover later that the degree of "desorder" inside the programs tends to grow even faster than with traditional languages. Thus, while it is easy to develop fast, brilliant solutions, it becomes difficult to extend them (say 6 months later). One sometimes feels as if the power of the language "revolts" against the programmer. To be clear, this is not a new problem; the "desorder" (or "software enthropy") is a problem plaguing every system based on software, in any language (since the "Mythical Man Month"). But the dismay comes when one begins to suspect that Perl solves nothing in this area (or that it makes things worse).

Enter this book: under a very unpretentious title/subtitle ("practices/coding style"), Damian Conway attacks this problem from the first page to the last. He does so not by inflicting the reader with a new set of abstract theories (like you would expect from an University professor); rather, he proceeds bottom-up, examining every one of the language components - data structures, control mechanisms, filters, transforms, regular expressions, built-ins, objects, class hierarchies - analyzing the way that they are traditionally 'written' (literally!). The objective is to rewrite them in order to answer concrete questions:
1) which is the most clear way that this can be written, not only for the super smart programmer, but also for regular programmers who will come after?
2) can we write this algorithm in order to facilitate extensions, minimizing the possibility that errors will be introduced?
3) which form offers the least impact on other adjacent components? ("ecologically friendy" code).
4) which is the impact of the solutions for system performance (cpu, memory)? which solution is the best compromise when the above issues collide?
5) after having seen the "best home solution", is there a CPAN module already doing this? then, use it (if your envirnoment allows).

It is not even possible to cite the "best parts"; every subject and proposed solution is a gem of programming and design intelligence. Take for example the discussion on "Naming" (ch 3) or on "Unnecessary/Necessary Subscripting" (chapter 6); yes, they don't sound exciting, but just take the time to apply the reccomendations to existing code that you have (perhaps accessing nested data structures), and examine the result. For me, it was remarkable (Data::Alias is a gift!).
But let's come to the most controversial proposals (see angry comments in postings): pattern matching and objects.

1) Pattern Matching: the proposal is to generalize the usage of /\A ... \z/xms expression. After trying it for some time (on my most complex regexp program), my conclusions were the following: yes, the expressions were a bit more complex (several times, I had to introduce character classes not needed before). However, I noticed this: while before I had to decide (for every regexp) the subset of modifiers (/xms) to use and then "design" the expression based on this choice, now each expression was just designed for ONE (same) case, no questions asked. This was particularly useful when debugging or modifying: instead of running to the right of the expression to read the modifiers and then switch brain cells to read the expression accordingly, I knew inmediately how to interpret it. In short, there is a huge "simplification" bonus: '/xms' means (if each letter can be present or absent) 8 different combinations; unless each letter is always present, and then you have 1! The advantage (ease of maintenance/extension) largely exceeded the drawback (more care writing the regexp), for me.

2) Objects: they are implemented as "inside-out" objects; in short, an "object" is (rather, has) an identifier into a private database of attributes, each described by a hash. Thus, if you had a large collection of object instances, we go from a large multitude of "small bundles" (one hash per object) to a few large hashes (one per attribute). This desecration of the "object-bundle" produces this result: it is now impossible for clients to access the object internal data.
Notice how this goes against all what Perl authors have proudly said for years; that "Perl objects do not enforce privacy (unlike those other languages...), but rather they ask the client to respect the contract; too bad for the client if he does not". Instead, Damian Conway suspects the exact opposite scenario: if users of the class "break the contract", and months later the class designer modifies the class internals, guess who the "pointed-hairy boss" will blame? It is intriguing that this insight on how the real world works comes from an university professor; and he is completely right (I would add this: even when the boss is not unintelligent, the needs of the "existing applications" will prevail, by inertia laws; unless you have an extraordinary collection of personalities in your office).

But the advantages of the new implementation go much further than preventing political clashes; see the benefits for Inheritance (no collision of attribute names), and for complex Class Hierarchies. Even the eternal problem of constructors under Multiple Inheritance ("diamond" case) is solved: in one of the most memorable observations, the author exclaims (p.378): "the real problem is not that there aren't enough constructor calls; it's that there are too many!". A fantastic solution follows; you can love it from an architectural standpoint, and from a programming one (see ex 16-9, where the class' parents are ejected from the top of a list, while the grand-parents enter from the back; in a few lines, the whole hierarchy is collected, and the calls to "Builders" can be automated). Talk about "practices, and coding style"; this is Architecture, Design, and Programming at their best!

One last note for novice programmers: do not see this as a book only for advanced programmers; on the contrary, it is useful at all levels in Perl. Students of "Learning Perl" or "Intermediate Perl" should begin to read (in parallel) relevant chapters of this book, so that at the same time that you learn new areas and skills, you simultaneously "polish" them.
In fact, the book's lesson is: software "Enthropy" or "Desorder" must (and can) be fought systematically, from day 1, from the first line of code; it does not matter if it takes a bit more time; just do the right thing.

Summary of Perl Best Practices

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 how software 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

Linux Books

Book Subjects
Most talked about in Linux Books
Linux TCP/IP Network Administration ImageLinux TCP/ IP Network Administration
by Scott Mann
Prentice Hall; Published: 2001-07-26; Paperback; Book
Best price: $8.99
Price in other shops: $54.99
Linux and Windows: A Guide to Interoperability ImageLinux and Windows: A Guide to Interoperability
by Ed Bradford, Lou Mauget
Pearson Education; Published: 2001-12-14; Paperback; Book
Best price: $10.25
Price in other shops: $44.99
Integrating Linux and Windows ImageIntegrating Linux and Windows
by Mike McCune
Prentice Hall PTR; Published: 2000-12-19; Paperback; Book
Best price: $26.68
Price in other shops: $39.99
Real World Linux Security: Intrusion Prevention, Detection and Recovery (Open Source Technology) ImageReal World Linux Security: Intrusion Prevention, Detection and Recovery (Open Source Technology)
by Bob Toxen
Prentice Hall PTR; Published: 2000-11-30; Paperback; Book
Best price: $3.99
Price in other shops: $44.99
The UNIX and Windows 2000 Handbook: Planning, Integration and Administration ImageThe UNIX and Windows 2000 Handbook: Planning, Integration and Administration
by Lonnie Harvel, David Webb, Steven Flynn, Todd Whitehurst
Prentice Hall; Published: 2000-05-14; Paperback; Book
Best price: $4.45
Price in other shops: $64.00
Linux Desk Reference (Open Source Technology Series) ImageLinux Desk Reference (Open Source Technology Series)
by Scott Hawkins
Prentice Hall; Published: 1999-11-30; Paperback; Book
Best price: $2.44
Price in other shops: $29.99
Linux User's Guide : Using the Command Line and Gnome With Red Hat Linux 9.0 - Textbook Only ImageLinux User's Guide : Using the Command Line and Gnome With Red Hat Linux 9.0 - Textbook Only
by Carolyn Gillay
Franklin Beedle & Associates; Published: 2004; Paperback; Book
Best price: $999.00
Linux: The Textbook ImageLinux: The Textbook
by Syed Mansoor Sarwar, Robert Koretsky, Syed Aqeel Sarwar
Addison Wesley; Published: 2001-07-12; Paperback; Book
Best price: $100.44
Price in other shops: $117.00
UNIX to Linux® Porting: A Comprehensive Reference ImageUNIX to Linux® Porting: A Comprehensive Reference
by Alfredo Mendoza, Chakarat Skawratananond, Artis Walker
Prentice Hall; Published: 2006-04-22; Paperback; Book
Best price: $41.20
Price in other shops: $69.99
RHCE Red Hat Certified Engineer Linux (Exam RH302) ImageRHCE Red Hat Certified Engineer Linux (Exam RH302)
by Michael Jang
McGraw-Hill Osborne Media; Published: 2004-03-30; Paperback; Book
Best price: $23.29
Price in other shops: $59.99
Similar Books and other products
Object Oriented Perl: A Comprehensive Guide to Concepts and Programming Techniques ImageObject Oriented Perl: A Comprehensive Guide to Concepts and Programming Techniques
by Damian Conway
Manning Publications; Published: 2000-01-01; Paperback; Book
Best price: $118.64
Mastering Regular Expressions ImageMastering Regular Expressions
by Jeffrey E.F. Friedl
O'Reilly Media; Published: 2006-08-15; Paperback; Book
Best price: $24.88
Price in other shops: $44.99
Mastering Perl ImageMastering Perl
by brian d foy
O'Reilly Media; Published: 2007-07-23; Paperback; Book
Best price: $22.59
Price in other shops: $39.99
Mastering Algorithms with Perl ImageMastering Algorithms with Perl
by John Macdonald, Jon Orwant, Jarkko Hietaniemi
O'Reilly Media; Published: 1999-08-25; Paperback; Book
Best price: $7.85
Price in other shops: $39.99
Effective Perl Programming: Ways to Write Better, More Idiomatic Perl (2nd Edition) (Effective Software Development Series) ImageEffective Perl Programming: Ways to Write Better, More Idiomatic Perl (2nd Edition) (Effective Software Development Series)
by Joseph N. Hall, Joshua A. McAdams, brian d foy
Addison-Wesley Professional; Published: 2010-04-29; Paperback; Book
Best price: $28.23
Price in other shops: $44.99
Perl Hacks: Tips & Tools for Programming, Debugging, and Surviving ImagePerl Hacks: Tips & Tools for Programming, Debugging, and Surviving
by chromatic, Damian Conway, Curtis "Ovid" Poe
O'Reilly Media; Published: 2006-05-15; Paperback; Book
Best price: $17.12
Price in other shops: $29.99
Perl Cookbook, Second Edition ImagePerl Cookbook, Second Edition
by Tom Christiansen, Nathan Torkington
O'Reilly Media; Published: 2003-08-28; Paperback; Book
Best price: $27.55
Price in other shops: $49.95
Programming Perl (3rd Edition) ImageProgramming Perl (3rd Edition)
by Larry Wall, Tom Christiansen, Jon Orwant
O'Reilly Media; Published: 2000-07-21; Paperback; Book
Best price: $19.55
Price in other shops: $49.99
Learning Perl ImageLearning Perl
by Randal L. Schwartz, brian d foy, Tom Phoenix
O'Reilly Media; Published: 2011-07-01; Paperback; Book
Best price: $22.49
Price in other shops: $39.99
Intermediate Perl ImageIntermediate Perl
by Randal L. Schwartz, Tom Phoenix, brian d foy
O'Reilly Media; Published: 2006-03-15; Paperback; Book
Best price: $21.00
Price in other shops: $39.99