I have learned through much pain that the most fun, comfortable way to program actually anything, is to deal with all errors when starting a new thing. Design how you're going to indicate errors (exceptions? return values? if so, as a struct, or as an enum?). Deal with incorrect inputs by returning errors. Then write tests checking all of those errors are being detected. And then start writing the substantive code. Then you have guaranteed-good inputs for the actual program/function, which is surprisingly nice. Any other approach is more painful and takes longer.

An unexpected (for me) illustration of this approach's value was very recent, when I was using the newly-incorporated Test::PDL to update all the tests of PDL to use is_pdl, which checks types, dimension, bad value patterns, NaNs, numerical values, and reports in some detail any failures. The tests thus modified are SO much simpler, with no need for extra code to dump any incorrect inputs, and have actually caught at least one bug (incorrect handling of converting a negative floating-point number into an unsigned value - on ARM, it gets a 0, even though on Intel it gets the INT_MAX+number+1).


In reply to Re^2: Does each DBI 'do' start a new transaction? by etj
in thread Does each DBI 'do' start a new transaction? by Anonymous Monk

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.