Now, I get how it's not needed, but the warnings in this documentation appear a bit hyperbolic. Are these warnings exaggerated?

Nope, sounds rather tame :)

Or is legacy code that still includes finish calls as an idiomatic way to communicate intent actually a “mistake” instead of merely wasted effort?

Its both :) its also neither :)

Its definitely not "idiomatic way" since the DBI docs tell you don't; Its part of the public API, the drivers have to implement it, but there isn't a single usage shown in the examples in DBI.pm, and you don't need or want it 99/100, so anytime it shows up its 99/100 a mistake , typically cargo-cult-ed

Also, documenting intent, what intent? That you're finished with the statement handle? I think undef $sth; documents that more clearly and universally :)!

However, I would like to understand the actual risk of needlessly calling finish, or if this is just an effort to get people to streamline their code?

The risk is an error message gets lost (esp if you're not using RaiseError); Calling finish modifies $sth attributes ... https://metacpan.org/source/TIMB/DBI-1.631/DBI.xs, https://metacpan.org/source/TIMB/DBI-1.631/Driver.xst, https://metacpan.org/source/ISHIGAKI/DBD-SQLite-1.42/dbdimp.c

I don't think its an effort to get people to streamline their code :) Because

Its kind of like calling  close $fh; except that it isn't

Its more kind of like calling  close $fh; close $fh; ... the $! gets obliterated

Its not unlike calling  $foo->DESTROY when  undef $foo; will do that

Its like using opendir/readdir/closedir ... its lower level interface you don't need most of the time

Possible use case for finish, is user clicks cancel button in a gui, there are still many results left, so program calls finish ... but in reality 99/100 you'd simply destroy undef $sth ... and you'd be handling errors with RaiseError... not manually checking

Yes, I've frequently written copy/pasted  $sth->finish even when all I really wanted was  $sth->commit; and  undef $sth; would have (probably) accomplished both (:IIRC...:); I'm not afraid to cargo-cult :)


In reply to Re: DBI and finish (risk of calling finish twice) by Anonymous Monk
in thread DBI and finish by wind

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.