Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Perl Best Practices

by wazoox (Prior)
on Jul 18, 2005 at 10:14 UTC ( [id://475691]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl Best Practices
in thread Perl Best Practices

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?

Replies are listed 'Best First'.
Re^4: Perl Best Practices
by TheDamian (Vicar) on Jul 19, 2005 at 00:24 UTC
    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).

      In which case the top level of the program needs to be running inside an eval{...} anyway (...)

      Mmmmmphf. Weren't exceptions about "less clutter" and "more readable code"? :)
      Another thing that bothers me with exceptions is that you can't see at the first glance which error will be correctly handled, or will simply receive the default treatment. After all you'll end up with special case code for every important error, whichever error management system you choose :)

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

      Be sure I'll buy it very quickly as soon as I'll have achieved "Object Oriented Perl" (mmmh, chapter 5 right now) :) Thanks for the brief explanation anyway... I have the howl book ("mastering regular expressions"), but missed time to master it yet :)

        In my experience, why an exception was thrown is rarely as important as that it was thrown.

        I.e. the calling code is almost never interested in why something didn't work out, it only needs to log that it couldn't complete it's own task, and the reason for it (so that you can see afterwards what went wrong). There is very seldom any active attempt to actually recover from the error in a very specific way, apart from perhaps waiting, doing it again etc.

        Disambiguating different reasons for the error and adjusting to that is better handled at a lower level of the code, closer to where the error occurred, and there you already have the proper granularity, i.e. that an exception occurred.

        /J

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found