Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl Best Practices

by Anonymous Monk
on Jul 15, 2005 at 16:34 UTC ( #475285=perlnews: print w/ replies, xml ) Need Help??

Perl.com has just published a great article from Damian Conway, called "Ten Essential Development Practices". Not so much an excerpt, but a sampling from his upcoming book.

Great reading, and no, I'm not here for the XP.

Comment on Perl Best Practices
Re: Perl Best Practices
by simonm (Vicar) on Jul 16, 2005 at 02:27 UTC
    I find it interesting that so few of these points are Perl-specific.

    Things like "write tests first", "use revision control", and "no premature optimization" are almost universal recommendations...

      Well, we should consider that the title of the article was "Ten Essential Development Practices", not "Perl Best Practices". ;-)

      From what I've seen and heard from the book, it goes into a much more detailed discussion about practices that are more specific to Perl, such as the (ab)use of subroutine prototypes, conventions for passing and using subroutine parameters, how to represent objects in Perl, etc.

      I find it interesting that so few of these points are Perl-specific.

      Indeed, even the two vaguely Perl specific ones:

      3. Create Standard POD Templates for Modules and Applications
      6. Agree Upon a Coherent Layout Style and Automate It with perltidy

      are generally applicable if you remove the POD and perltidy bits.

      I find it interesting that so few of these points are Perl-specific.
      It's interesting you mention that. The original set of ten I had planned to use were much more Perl-centric (so much so that we wouldn't have called them "Essential Development Practices", but rather "Essential Perl Coding Practices"):
      1. Always use strict and use warnings.
      2. Use grammatical templates when forming identifiers.
      3. Use lexical variables, not package variables.
      4. Label every loop that is exited explicitly, and every next, last, or redo.
      5. Don't use bareword filehandles; use indirect filehandles.
      6. In a subroutine, always unpack @_ first, using a hash of named arguments if there are more than three parameters.
      7. Always return via an explicit return.
      8. Always use the /x ,/m , and /s flags, and the \A and \z anchors.
      9. Use capturing parentheses in regexes only when deliberately capturing, then give the captured substrings proper names.
      10. Never make variables part of a module's interface.

      But as I started extracting these guidelines from the book, I realized that they relied on the reader understanding and accepting other, earlier guidelines, which in turn relied on other guidelines, etc. etc. The book is deliberately put together that way, so that the recommendations work harmoniously together and form a coherent approach to Perl programming. Unfortunately that made it hard to isolate just ten of the Perl-specific guidelines and still have them make sense.

      That said, if you want to get a better sense of the (great majority of) Perl-specific advice in the book, take a look at the beta chapter we have online.

      Things like "write tests first", "use revision control", and "no premature optimization" are almost universal recommendations...
      ...that people universally don't follow. Hence we thought these ten, though not especially Perlish, would still be a valuable reminder. ;-)

        Your article is so great I declared it mandatory reading for our developers and interns :) There's only one point I'd discuss, it's the "always use exceptions" rule. Exceptions suffer exceptions :), for instance for programs that mustn't die whatever happens (daemons, GUI tools for complex jobs, etc).

        And concerning the 8th perl coding practice ( Always use the /x ,/m , and /s flags, and the \A and \z anchors.): could you explain it a bit?

        The original set of ten I had planned to use were much more Perl-centric (so much so that we wouldn't have called them "Essential Development Practices", but rather "Essential Perl Coding Practices")

        That sounds like it'd also be a good article, although I understand your point about the additional context required to undetsand these more Perl-specific points.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlnews [id://475285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-12-22 11:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls