Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: Perl Best Practices

by TheDamian (Priest)
on Jul 19, 2005 at 00:24 UTC ( #475932=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^4: Perl Best Practices
Re^5: Perl Best Practices
by wazoox (Prior) on Jul 19, 2005 at 14:53 UTC
    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

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

        That's absolutely right. However, if a particular exception is caught from a function you didn't anticipated, you may very well end with an incoherent state. Well, There's a nice article on this matter here : Exceptions and another one there which is even better :Cleaner, more elegant, and harder to recognize . I understand very well the way exceptions match the "laziness and hubris" state-of-mind, however I feel more like Joel on this ;)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2014-07-22 08:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (107 votes), past polls