Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Just a simple real life example, derived from my day to day work:

An application that deals with item prices delivered by third party servers (so, unknown ahead of time) and does a change check before each action that has to do with actual cash. If the price changes, it backs out and tells the user, with the message highlighted in red or green. Prices are displayed in full euro values at all times for brevity.

With exceptions:
die { type => 'PriceChange', amount => -123 };
The exception handler can recognize it by eq'ing the type and derive the direction from doing a numerical inspection of the amount and then shunt the whole thing through a template generator.

With strings:
die "PriceChange: The price changed by -123 Euro.";
The exception handler does:
$error =~ m/^(\w+)\:.* ([-\d]+) /; if ( $1 eq 'PriceChange' ) { my $direction = determine_direction( $2 ); return price_change_error( $error, $direction ); } else { return "UNKNOWN ERROR!"; }

Both work fine. Now management decides: "We want the decimals displayed!"

So the die errors get changed:

die { type => 'PriceChange', amount => -123.45 };
die "PriceChange: The price changed by -123.45 Euro.";


You see what happens, right? And just in case you try to argue "this code is dumb", yes it is. But let me assure you it's tame against the shit i've seen in production over the years.


And lastly, i'm not going to try and address your wall of text at the bottom there. I dislike Java as well, i dislike OO as well and only use it when i can't think of a lispy way to do something. But i never labeled you as an OO-hater, you made that up on your own. I merely said that i think you're too busy hating Java to allow yourself to see that E::C has little to do with it at the core.

In reply to Re^18: eval to replace die? by mithaldu
in thread eval to replace die? by hsmyers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (11)
    As of 2014-07-25 07:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (169 votes), past polls