Edinburgh Castle
Perl Medic - Transforming Legacy Code
AuthorPeter J. Scott
PublisherAddison Wesley
ISBN0-201-79526-4
Date2004
Pages312
Price£26.99
ReviewerRory Macdonald
Cover image for Perl Medic : Transforming Legacy Code

Have you ever been given the task of maintaining someone else's Perl code? If you use Perl at work then chances are that you have. Professionally, I have adopted my fair share of horrific Perl code, so I was eager to hear what Scott had to say on the matter. My eagerness can only partially account for reading the book cover to cover in one sitting. The rest must be put down to Scott's clear, gentle and engaging exposition of the topics covered; periodically parting the waves to reveal just enough of perl's inards to explain a "how" or a "why".

Being given legacy code to fix or maintain can seem overwhealming. So, early on, before setting about assessing and mangling adopted code, Scott briefly addresses what to do as soon as you're landed with someone else's code. The author also touches on the divisive but important topic of coding styles, where the message boils down to "pick one".

In a similar vein to Tom Christiansen's "Perl Hierarchy", Scott chooses to set out his own 10 level Perl coder classification table. References to this table are used sparingly throughout the book to indicate the level of "sophistication" of the particular topic being covered.

Testing and debugging module essentials are covered with such ease and clarity that the reader may have to come up with some novel excuses to avoid making use of them. As is the case with other core/utility modules mentioned in the book, the user is sensibly left to perldoc for deeper details.

But just how "in the trenches" is this book? The chapter on upgrading provides fine coverage of a real world legacy code maintainance topic; trying to spot which version of perl your adopted code was written to run under. On a per-version basis, the author provides a list of tell-tale signs/code fragments associated with each release, along with a list of new features and gotchas which were introduced with that version.

Scott also gives a chapter over to some well illustrated sabre-rattling on the matter of disciplined code, specifically relating to sane variable scoping and use of pragmas. Also of great use to the Perl Medic are the examples of common "Cargo Cult Perl" code and their cleaner, more maintainable replacements.

The author starts to wrap things up with some common sense advice about using CPAN modules, and on the way manages to fit in some useful code bullet-proofing suggestions which the mainstream reader might not currently be making use of.

Using a short Perl 4 CGI program as the patient, the Perl Medic case study puts into practice many of the tactics and lessons presented in the book. While the code sample is short (~90 lines), it is well chosen to trigger a variety of considerations in making modifications, and rather than prove boring the case study is perfectly digestible.

Summary

Other than a couple of minor niggles with the back cover blurb (citing an unsupported statistic and claims to be "the first systematic guide to Perl software engineering") the book easily reaches it's goal of providing the reader with insightful guidance on understanding, maintaining and refactoring adopted Perl code.

Whether you are adopting or sorting your own legacy code, I can highly recommend this book for the professional Perl coder who has been round the block a few times.

Table of contents

	Preface
	Ch1 : Introduction (First Response)
	Ch2 : Surveying the Scene
	Ch3 : Test Now, Test Forever (Diagnosis)
	Ch4 : Rewriting (Transplants)
	Ch5 : The Disciplined Perl Program
	Ch6 : Restructuring (The Operating Table)
	Ch7 : Upgrading (Plastic Surgery)
	Ch8 : Using Modules (Generic Enhancement)
	Ch9 : Analysis (Forensic Pathology)
	Ch10 : Increasing Maintainability (Prophylaxis)
	Ch11 : A Case Study
	Ch12 : Conclusion (Prognosis)
	App A : Source Code
	App B : Intro to Perl
	Bibliography
	Index
	About the Author
faded separator

Page maintained via github.com/edinburgh-pm/edinburgh.pm