Point taken. I was thinking about stuff like a validation function, which in this model would be about three steps down the call chain from the client's get() call. Code like that would be designed to fail at specific times and for specific reasons, and is the best source for information about which zero/one/many conditions the input failed to meet.

Silent-on-success/noisy-on-failure is conceptually similar to throwing an exception. The code up the call chain that tests/reads the result string is vaguely like a series of exception handlers. You do have to organize the code a little differently, walling off any code that shouldn't execute with bad data behind a conditional, but in most cases that isn't too difficult. The main trick is to avoid putting a big list of things that can fail all in the same function.

I generally solve that problem by iterating over a list of function pointers and dropping out of the loop if something fails. And whenever possible, I prefer to run the whole loop, collect all the errors, and then proceed or exit based on the existence/nonexistence of one or more failures. That keeps me from ripping out what little hair I have left because of the old, "okay, I solved the problem that made the code choke there, and now it's choking in the next condition three lines further on," scenario.

Sometimes you do run into logic that requires exceptions, but this works pretty well for me most of the time.

The overloaded FALSE string does sound like fun, though.. I may have to play with that one of these days when I'm feeling silly.


In reply to Re^4: Need help with a conceptual speed bump by mstone
in thread Need help with a conceptual speed bump by mstone

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.