Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^20: eval to replace die?

by mithaldu (Monk)
on Oct 09, 2010 at 20:08 UTC ( [id://864416]=note: print w/replies, xml ) Need Help??


in reply to Re^19: eval to replace die?
in thread eval to replace die?

With an exception that is a structure there is no need to correct any problem. The test suite still passes because there is no problem.

Which was the whole point of this entire debate: It is much easier to run into trouble by using string-only errors.

Replies are listed 'Best First'.
Re^21: eval to replace die?
by BrowserUk (Patriarch) on Oct 09, 2010 at 20:28 UTC
    It is much easier to run into trouble

    Coding a feature change is not "running into trouble". Doing a half-assed job of it is just sloppy. Allowing that sloppiness to get into production is bad process. You cannot correct bad process by over-engineering.

    Your derived contrived example code made no sense.

    There was no reason to parse the error message. You never did anything with the results of the parsing.

    Which was the whole point of this entire debate:

    You think? Read again.

      You cannot correct bad process by over-engineering.
      You are right, i cannot. I can merely lessen the chance of others actions based on bad process being a danger and i will gladly do so.
      There was no reason to parse the error message. You never did anything with the results of the parsing.
      There was a reason, since i did something with the result, which i stated in the second paragraph. The value of the change (positive/negative) determined the direction of the change and based on that a css style which is used to colour the message. This not contrived, but slightly anonymized code i've encountered, written by others.
      You think? Read again.
      I would like to ask you to look at the original starting post of this node tree and ponder the intent of the message the user is asking the perlmonks about. I am of the opinion that it correlates very closely with what i said.
        The value of the change (positive/negative) determined the direction of the change and based on that a css style which is used to colour the message.

        First observation, if the only purpose of the parsing is to detect positive or negative--the regex was wrong. A simple $message =~ /-/ would probably suffice, and create parity with your exception solution in as much as you could change the datatype of the value without requiring a change in the exception handling mechanism.

        Not that I would advocate that solution, but it demonstrates the contrivance of your example. It conflates two exceptions as one.

        The correct solution for the problem of two different possible errors, is to raise the appropriate of two exceptions. One for less; one for more. Each with a different error number. Then there is no purpose in parsing the error; a simple compare takes the appropriate action.

        I would like to ask you to look at the original starting post

        Out of courtesy, I looked again. And I reached the same conclusions.

        Nothing in the OP requires, nor would benefit from, a structured exception. What corrective action could be taken to correct a failure to retrieve a file? None!

        The only possible action is to report the error and terminate. Whether it be that the file does not exist;, or has the wrong permission; there is no point in trapping the die, when the only reasonable action is to do exactly what die does. And all to satisfy the scurrilous default from perl-critic.

        Recommending moving to using E::C, in order to silence perl-critic, when the only possible action is to (laboriously) emulate exactly what die does, is ...

        (*)Did you do me the courtesy re-reading each evolution of my posts, within the context of the posts to which I replied? (Betting not!)


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found