Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl Best Practices

by simonm (Vicar)
on Jul 16, 2005 at 02:27 UTC ( #475399=note: print w/ replies, xml ) Need Help??


in reply to Perl Best Practices

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...


Comment on Re: Perl Best Practices
Re^2: Perl Best Practices
by itub (Priest) on Jul 16, 2005 at 05:26 UTC
    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.

Re^2: Perl Best Practices
by adrianh (Chancellor) on Jul 16, 2005 at 17:32 UTC
    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.

Re^2: Perl Best Practices
by TheDamian (Priest) on Jul 18, 2005 at 04:47 UTC
    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?

        Exceptions suffer exceptions :), for instance for programs that mustn't die whatever happens
        In which case the top level of the program needs to be running inside an eval{...} anyway, to protect it from intrinsic exceptions like divide-by-zero or call-on-missing-method. So exceptions are still okay, as they'll always be caught.
        And concerning the 8th perl coding practice: could you explain it a bit?
        Sure, but an adequate explanation is about 30 pages long. Which is why I put it in a handy book, very soon to be available from most good bookstores. ;-)

        Briefly, always using /x allows you to set out regexes readably, and to comment them. Always using /ms makes Perl regexes work the way most people expect them to work, and prevents very subtle edge-case errors. Using \A and \z is essential for saying what you mean under /m (which you'll always be using).

      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: note [id://475399]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-08-01 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (257 votes), past polls