Perl Best Practices Paperback – Jul 22 2005
|New from||Used from|
Customers Who Bought This Item Also Bought
No Kindle device required. Download one of the Free Kindle apps to start reading Kindle books on your smartphone, tablet, and computer.
Getting the download link through email is temporarily not available. Please check back later.
To get the free app, enter your mobile phone number.
"If you are looking for a book to teach you how to program Perl, this is definitely not what you need. Also, if you are cranking out quick Perl scripts to solve one-time tasks, it might not be worth the effort to read this book. However, if you are fairly comfortable with the language and are looking for ways to improve your code, this book would be a wonderful addition to your bookshelf." - James Mohr, Linux Magazine, November 2005
Standards and Styles for Developing Maintainable CodeSee all Product Description
Most Helpful Customer Reviews on Amazon.com (beta)
Don't modify via $_ (too easy to screw things up)
Use hashes for arguments if arguments > 3 (trackability)
Use Croak instead of die (Croak gives more info, better for debugging)
Use ' ' instead of " " when no interpolation (less ambiguity)
Don't use unless (complication and confusion).
use /xms in regexes (for readability, and avoiding mistakes)
test when closing or opening a file
A few of the reviews here are 1 star. IMO these are people to which "freedom" is more important than "group code maintainability". This should really be the third Perl book for anybody, after Learning Perl and Intermediate Perl.
For those wanting to test their code against this book, there is a Perl Module, Perl::Critic, that does the job.
I strongly recommend that anyone writing Perl professionally should read this. But I do have an issue or two with it. For example, I think it was wrong to start off with a rule about brackets. That's one thing that people are religious about and there is no real reason to go one way or another. That starts the book on a weak premise. From which it quickly recovers.
Overall, a fantastic book. Well written and researched. It's the kind of book I would expect from Damian Conway and I wasn't let down. A must-read for Perl programmers.
He brings up so many topics, some well discussed and some more esoteric and presents practical benefits that almost anyone who reads it, I expect, will come away with some new habits. I think there are very few books I've ever read that could convince people to change their programming ways - years of developing versus a couple hours of reading. You may not agree with every point he makes, but he'll make you think about why you do certain things, and that can't but help make you a better programmer.
I can not recommend this book enough to any perl developer out there. If you're new to it or been doing it for years, this book is for you.
The goal of this book is teaching Perl programmers how to write their code for both readability and maintainability. We've all been there - we wrote code months or years ago, or we're just picking up someone else's code and we need to go back in and change something. The challenge is, whether it's been a long time or it's someone else's code, it takes time to remember what we were trying to do. If we are inconsistent in our coding style, it can be difficult to switch to the style of the code we're working in.
Example: (quoting the book, p 453)
Don't be clever.
Tied variables are a clever idea, but "cleverness" is the
natural enemy of maintainable code. Unfortunately, Perl
provides endless opportunities for cleverness.
For example, imagine coming across this result selector in
| $optimal_result = [$result1=>$result2]->[$result2=>$result1];
This syntactic symmetry is very elegant, of course, and
devising it obviously provided the original developer with
a welcome diversion from the tedium of everyday coding. But
a clever line of code like that is a (recurring) nightmare
to understand and to maintain, and imposes an unnecessary
burden on everyone in the development and maintenance teams.
Cleverness doesn't have to be nearly that flagrant either.
Having finally deduced that the example expression returns
the smaller of the two results, you would almost certainly
be tempted to immediately replace it with something like
| $optimal_result = $result1 <= $result2 ? $result1 : $result2;
While that's certainly an improvement in both readability
and efficiency, it still requires some careful thought to
verify that it's doing the right (i.e., minimizing) thing.
And everyone who maintains this code will still have to
decode that expression--possibly every time they come
However, it's also possible to write that same expression
in a way that's so obvious, straightforward, and plain-
spoken that it requires no effort at all to verify that
it implements the desired behaviour:
| use List::Util qw( min );
| $optimal_result = min($result1, $result2);
It's not "clever" and it's even marginally slower, but
it is clean, clear, efficient, scalable, and easy to
maintain. And that's always a much better choice.
If you must rely on cleverness, encapsulate it.
If you never buy this book, at least go to your local library and check it out.
Look for similar items by category
- Books > Computers & Technology > Computer Science
- Books > Computers & Technology > Operating Systems > Linux
- Books > Computers & Technology > Operating Systems > Unix
- Books > Computers & Technology > Programming > Languages & Tools
- Books > Computers & Technology > Programming > Software Design, Testing & Engineering > Software Development
- Books > Computers & Technology > Programming > Software Design, Testing & Engineering > Structured Design
- Books > Computers & Technology > Software > Natural Language Processing
- Books > Computers & Technology > Web Development > Programming
- Books > Qualifying Textbooks - Fall 2007 > Computers & Internet
- Books > Textbooks > Computer Science & Information Systems > Computer Science
- Books > Textbooks > Computer Science & Information Systems > Operating Systems
- Books > Textbooks > Computer Science & Information Systems > Programming Languages
- Books > Textbooks > Computer Science & Information Systems > Software Design & Engineering