Slashdot Mirror


Perl Best Practices

honestpuck (Tony Williams) writes "I have to admit that I can bristle at books that try to preach, so Perl Best Practices was on a hiding to nothing when I came to review it. I also have to admit to being torn about the author -- after all, he is one of those poor fools who insist on living in cold, unenlightened Melbourne, while I live in vastly superior Sydney. On the other hand, how can I dislike a man who manages to place a quote that involves my favourite character, Lady Bracknell. from my favourite comic play, 'The Importance of Being Earnest,' in the first few pages of his book?" Read on for Williams' review. Perl Best Practices author Damian Conway pages 492 publisher O'Reilly Media rating 8 reviewer Tony Williams ISBN 0596001738 summary Methods of coding to improve your Perl software

Many years ago I read a marvelous article that explained why so may early editors and word processors supported the keyboard commands of WordStar. When it's first born, a baby duck can be easily convinced that almost anything is its mother. The small bird imprints, and it takes a lot to shift its focus. "Baby Duck Syndrome" affects programmers in a number of ways, not just their choice of editor, and Conway is walking right into the middle and arguing with your imprinting on almost every page. A brave man; fortunately he has the street cred to make you at least listen.

So I carefully placed my bias and bigotry in the bottom drawer and prepared myself. I discovered a well-written, informed and engaging book that covers a number of methods (hey, 256 rules, come on Derrick, 2 ^ 8 rules can't be a coincidence!) for improving your Perl software when working in a team. That means all of us when you remember an adage a guru once told me: "Every piece of computer software, no matter how small, involves at least a team of two -- me, and me six months from now when I have to fix it." Conway puts it differently "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."

The first chapter outlines the why and where of the book. The why is to improve your code with three goals; robustness, efficiency and maintainability. The chapter finishes with a short exhortation to us to "rehabit." Don't like the word much but I applaud the aim.

Conway is far from timid. He jumps right in to the deep end of the wars, with formatting the appearance of your code. I thought the chapter was brilliantly written until he told me I shouldn't "cuddle else statements," at which point I realized what an ill-informed idiot he was. Oh, hang on. Hey, that almost makes sense. OK, that's a cogent argument for your point of view, Conway. I also have to admit that earlier you did say that your rules for this bit weren't gospel, that if you wanted a variation that was OK, just have a standard and make sure you can support it with a code prettier. Perhaps not a total idiot after all.

After successfully negotiating those shark infested waters, Conway -- obviously a man who knows no fear -- wades into naming conventions. Once again he gives coherent arguments, pointed examples and counterexamples. It all makes sense.

The book's page at O'Reilly has an example chapter and a good description, but no table of contents so here's a quick list of the headings:
  1. Best Practices
  2. Code Layout
  3. Naming Conventions
  4. Values and Expressions
  5. Variables
  6. Control Structures
  7. Documentation
  8. Built-in Functions
  9. Subroutines
  10. I/O
  11. References
  12. Regular Expressions
  13. Error Handling
  14. Command-Line Processing
  15. Objects
  16. Class Hierarchies
  17. Modules
  18. Testing and Debugging
  19. Miscellanea
Suffice to say that Conway leaves no corner of Perl uncovered, offering well-reasoned and well-explained advice on improving your Perl code.

The book is also well-written and well-edited. The order of topics covered is a sensible one, and the book is appropriately structured. It reads and feels as if you are being given the wisdom from many a hard-won battle coding and maintaining Perl code.

My one complaint is that I found it dry: you are reading through pages of argument and examples without much relief. Perhaps this book might be best digested in a number of chunks, making the effort to use the ideas from each chunk for a while before moving on to the next.

Every so often I read a book from O'Reilly that makes me fear that they are slipping, then along comes a book like Perl Best Practices, and I'm reminded that when it comes to Perl, O'Reilly authors wrote the book. Once you've rushed through Larry's book and learnt the finer points with Schwartz and Phoenix's 'Learning' titles, you may well find that this is the perfect volume to complete your Perl education. If you believe your Perl education is complete, then buy this volume and I'm sure you'll find a lesson or two for yourself.

This book is not really aimed at the occasional Perl programmer (though many of us would probably benefit from its wisdom), but at the person who is professionally programming in Perl and wants to produce better quality, more easily maintained code. For this person Perl Best Practices is a 9/10. For the rest of us, the 'rehabiting' process might be a little too arduous; personally, I'm going to pick a few of the chapters and work on those for a while, maybe naming conventions and variables. For me I'll give it an 8.

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

22 of 288 comments (clear)

  1. Smile by kerohazel · · Score: 4, Funny

    If it looks like an emoticon, your Perl is probably syntactically correct. ;)

    --
    Skype is too convoluted... Now I'm reverse-engineering the Kyoto Protocol.
    1. Re:Smile by Phroggy · · Score: 4, Funny

      It's pretty annoying to paste perl code into an IM conversation and wind up with a big yellow smiley face in the middle of your regex, though.

      Try not to let my sig scare you too much.

      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
    2. Re:Smile by Anonymous Coward · · Score: 1, Funny

      It's not a smiley face -- that's just his regular expression [^:-].

  2. Grammar Best Practices by Anonymous Coward · · Score: 0, Funny

    "I have to admit that I can bristle at books that try to preach, so Perl Best Practices was on a hiding to nothing when I came to review it."

    me fail english? unpossible!

  3. Characters per line by RealityMogul · · Score: 3, Funny

    Perl programmers always say they can do anything in one line of code. Does this book finally set a limit on how many characters can be in that one line?

    1. Re:Characters per line by Karma_fucker_sucker · · Score: 3, Funny

      That would be good. I would also like to create an error handling module called "Neklace". So, a hard error handling routine would make a call into Perl Neklace, becuase you're fucked.

      --
      Evil people don't think they're evil. - George Lucas, Making of Ep III
    2. Re:Characters per line by Phillup · · Score: 2, Funny

      Maybe I'm getting a little old... but I'd definitely call it a *soft* error after the neklace part happens. At which point you're fucked. (past tense)

      ;-)

      --

      --Phillip

      Can you say BIRTH TAX
  4. Obligatory joke by Weaselmancer · · Score: 3, Funny

    Perl Best Practices, page 1.

    Use Python.

    Ba-dump-bump! Thanks, I'll be here all week. Be sure to tip your waitresses.

    --
    Weaselmancer
    rediculous.
    1. Re:Obligatory joke by Anonymous Coward · · Score: 3, Funny

      Python Best Practices, page 1.

      Use Ruby.

      Ba-hiss-hiss-hiss! Good bye you slimey snake.

  5. Buzzkill by red_dragon · · Score: 4, Funny

    What's the point of using Perl if your code suddenly becomes intelligible? After all, there is more than one way to obfuscate it.

    --
    In Soviet Russia, Jesus asks: "What Would You Do?"
  6. Best Practice? by kevin_conaway · · Score: 1, Funny

    Don't write it.

    /I kid because I love.

    1. Re:Best Practice? by baadger · · Score: 4, Funny
      Warning: main(php/rss_parse.inc): failed to open stream: No such file or directory in /home/groups/p/py/pyscrabble/htdocs/inc/about.php on line 5
      Fatal error: main(): Failed opening required 'php/rss_parse.inc' (include_path='') in /home/groups/p/py/pyscrabble/htdocs/inc/about.php on line 5
      ... yeah because PHP is working out so well for you.
  7. Ay mate? by boomgopher · · Score: 2, Funny

    after all, he is one of those poor fools who insist on living in cold, unenlightened Melbourne, while I live in vastly superior Sydney. On the other hand, how can I dislike a man who manages to place a quote that involves my favourite character, Lady Bracknell. from my favourite comic play, 'The Importance of Being Earnest,' in the first few pages of his book?"

    Oh, you do slay me, mate.

    Is this like http://slashdot.co.au/ or something?

    --
    Your hybrid is not saving the environment. Its purpose is to make you feel good about buying something.
  8. This holds true by ICECommander · · Score: 5, Funny

    My Data Structures professor once said: "Perl is a write-only language" :)

    --
    All your Sybase are belong to us.
  9. Re:Wordstar keybindings by bhirsch · · Score: 2, Funny

    Amazing how the importance of typing one-handed has never evaded software engineers.

  10. Syntax problem by lullabud · · Score: 4, Funny

    Being a Python programmer, not a Perl programmer, I'm sure you won't be angry if I point out your syntax problem: you forgot the semi-colon. It's a common mistake though. The proper syntax is:

    use Python;

  11. Re:Best Best Practice: Don't Bloat Perl by rpresser · · Score: 2, Funny

    Sure there is. Brainf**k, for example, which has only eight instruction types. Or Malbolge, where you can peruse all existing programs in an afternoon.

  12. Re:Read It by Chysn · · Score: 2, Funny

    Just realized, as soon as I hit submit, that I reversed $ and ^. Guess that sort of makes the case for \A and \z. But not because they make people look them up.

    --
    --I'm so big, my sig has its own sig.
    -- See?
  13. Re:A "best-practice" in Perl is like... by rpresser · · Score: 4, Funny

    000100 IDENTIFICATION DIVISION.
    000200 PROGRAM-ID.     HELLOWORLD.
    000300
    000400*
    000500 ENVIRONMENT DIVISION.
    000600 CONFIGURATION SECTION.
    000700 SOURCE-COMPUTER. RM-COBOL.
    000800 OBJECT-COMPUTER. RM-COBOL.
    000900
    001000 DATA DIVISION.
    001100 FILE SECTION.
    001200
    100000 PROCEDURE DIVISION.
    100100
    100200 MAIN-LOGIC SECTION.
    100300 BEGIN.
    100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
    100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
    100600     STOP RUN.
    100700 MAIN-LOGIC-EXIT.
    100800     EXIT.

  14. Re:Best Best Practice: Don't Bloat Perl by Jherek+Carnelian · · Score: 2, Funny

    I don't think there's any language that can be fully understood after a 2-semester course.

    I disagree. Most people I know are able to completely master pig latin with just a couple of days of study and use.

  15. Perl Best Practices by fforw · · Score: 3, Funny

    1. Don't

    --
    while (!asleep()) sheep++
  16. Re:Perl best practice number 1 by Anonymous Coward · · Score: 3, Funny
    Use a better fucking language!

    They have languages for that?! Oh man am I clueless.