Slashdot Mirror


Perl Medic

Craig Maloney writes "Anyone who codes in Perl can relate to working on other people's code. Sometimes the code will thankfully include "use warnings" and be a joy to maintain. More likely, though, the code will have so many warnings that the useful output is long gone in the stratosphere of your scroll buffer. Even good code written for earlier versions of Perl can become aged and decrepit, requiring elderly modules that may or may not work with newer versions of Perl. Maintaining this code can be a hassle, but fortunately Perl Medic: Transforming Legacy Code (referred to for the duration of the review as Perl Medic) provides some very useful tips for getting through these migrations, and will help the next person maintaining your code." Read on for the rest of Maloney's review. Perl Medic author Peter J. Scott pages 312 publisher Addison Wesley rating 8 reviewer Craig Maloney ISBN 0201795264 summary A great collection of Perl wisdom and tips for experts and other patient Perl acolytes.

One of the goals of Perl Medic is to transform code from stylistically poor and unmaintainable into stylistically sound, maintainable and testable code. The format of Perl Medic is very similar to books like The Pragmatic Programmer or The Practice of Programming. Perl Medic shows the reader best practices by example. Some of the chapters are checklists of practices that will help improve your ability to manage and wrangle the code, while others are lists of patterns and practices you should avoid, and should replace with the examples provided. This format very readable, and provides an excellent forum for gleaning what ways to improve the code.

Perl Medic is designed with experienced coders in mind. Topics are presented as if the reader may be using these ideas already in their code, whether good or not. While the advice is good, the presentation may be confusing for beginner and intermediate programmers who aren't intimately familiar with the concepts. I found myself re-reading several topics to try and grasp what the author was trying to convey. After several readings of the section on test harnesses, I still needed help, and ran to the Perl documentation to better understand what the author was saying. Certain advice is also presented, only to have it countered in the next section. Most Perl programmers are familiar with the '-w' switch, which turns on warnings in a Perl program. The pragma 'use warnings' is introduced as a way to turn on warnings for just the code being worked on without displaying the warnings of the modules included in the program. In the next section, the author points out that it might be a good idea to put '-w' in there to see if there are any issues in the modules you may be including. While this advice may be intuitive for experienced Perl coders, the beginner may be confused. "Should I use '-w', or should I use 'use warnings'" she may ask herself.

The book also suffers from a case of being too brief in some sections. In section 2.3.1 (Gobbledygook) the reader is directed for help on how to turn a partially obfuscated program into more intelligible code; a very useful skill indeed. The author redirects the reader to section 4.5 where the utility perltidy is discussed with further detail, but before ending the section, the author also introduces the module 'B::Deobfuscate' along with a URL. No mention of how to use it is provided. In section 6.4 (Debugging Strategies) the author gives advice on how to debug a program. His advice: "Divide and Conquer". While there is debugging advice throughout the book, it's a little frustrating to see a section specifically designated "Debugging", with only one subheading under it. The organization of some of the topics feels artificial, and perhaps should be reorganized in future editions.

Underneath these faults, though, Perl Medic is a great book. Chapter 11 (A Case Study) should be required reading for coders inheriting Perl projects. This chapter is a blow-by-blow account of the author's work in transforming a simple LDAP application from Perl 4 into a robust Perl 5.8 application. The author is very candid about what decisions were made in the code transformation, and why certain elements were addressed in the way they were addressed. One particular element is an elderly module used for the LDAP lookups themselves. The author details the process used to determine a better module to replace this module, and guides the reader through each of the steps required to change the code to use this new module. The decisions the author uses to make this code work under the new environment are enlightening for anyone planning a migration of Perl code into a newer environment. Chapter 7 contains the versions of Perl from Perl 4 up until 5.8.3, and elaborates on what changed between the versions (very helpful for those who are planning an upgrade from 5.003 to a more recent version of Perl). Chapter 9 (Analysis) has very useful tips for not only debugging you program, but for using the Perl Debugger and getting the most out of your debugging session.

Perl Medic is recommended for anyone who is tasked with maintaining or writing Perl Code. While the examples are written with experienced coders in mind, beginners will do well to use this book for areas to focus on while they learn the language. Inheriting code can be a daunting task, but with a book like Perl Medic, you'll have the tools at hand to help ease the work ahead into a more manageable task. And you'll make it easier for "the next guy".

You can purchase Perl Medic: Transforming Legacy Code from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

5 of 194 comments (clear)

  1. Re:Nay by jargoone · · Score: 3, Informative

    Yeah. Because PHP is great at non-web applications.

  2. not just for legacy code by consumer · · Score: 5, Informative

    This is the best book I've ever read about how to write clear and maintainable Perl code. The advice is solid and up-to-date with discussions of perltidy, modern web techniques, etc. I would recommend this book to anyone who writes Perl, just as a style guide.

    1. Re:not just for legacy code by Hercynium · · Score: 3, Informative

      Hear, hear! I have had this book in my desktop library since i bought it eight months ago. While it's certainly too short to truly cover the topic completely, this book has remarkable depth, and is still quite easy to grok. You can read it cover-to-cover or flip around and always find some useful advice. Don't make the mistake of thinking this book is too short to be useful... It's filled with hints and links to more information. Heck, nowadays, all books should be filled with links and references; printed materials too often become obsolete too quickly!

      (Normally I'm a grammar/spelling nazi for myself... but I've been coding in PHP all day and I've lost the will to fight for correctness.)

      --
      I'm done with sigs. Sigs are lame.
  3. If you liked Peter's book, attend Peter's workshop by TomDLux · · Score: 2, Informative

    I agree, perl medic is a great book, influential in encouraging and developing good habits.



    Peter will be speaking, though not on the same topic, at YAPC:2005, June 27, 28, 29 in Toronto. There's a whole day's worth of workshops on perl6, including PUGS, most of a day on testing, as well as threads on DBI, CGI, and lots of other workshops. Register now! At $85US for registration, it's the best bargain you'll find this year.


    If you are planning to attend, Book your hotel room soon. The host hotel is only guaranteeing room availability till next weekend. There's a huge conference coming to Toronto a few days after YAPC, so the hotel wants to start making rooms available for early arrivals. Not that all the rooms will disappear the first day, but you wouldn't want to be disappointed, would you?



  4. Re:Nay by Anonymous Coward · · Score: 1, Informative

    "Actually it started out as an apache module."

    Actually, you're totally wrong.

    "It stands for 'Pre Hypertext Pages'."

    No, no, and no again. It never stood for that, not once, not ever. I'm not even going to dive into the rest of what you wrote, I'll just back myself up with real facts, unlike yours.

    I quote:

    "PHP/FI was created by Rasmus Lerdorf in 1995, initially as a simple set of Perl scripts for tracking accesses to his online resume. He named this set of scripts 'Personal Home Page Tools'."

    Thanks. Now please stop trying to prove people wrong unless you know your OWN facts first.