Bare return; does the right thing in both scalar and list contexts.

I'm assuming that you are defining "the right thing" as "being false". For many functions, the "right thing" even in a list context is "return one scalar". Next we'll replace NaN with an empty list for the math functions.

If you aren't assigning the list (return value), then the boolean nature of what is returned doesn't matter (well, if you are just checking the return value, then you aren't in a list context and return undef; works fine). Do you find yourself writing a lot of code where you assign a single scalar to an array and want to test that assignment in a boolean context? I don't, and I think there are good reasons why I don't.

Do you find yourself constructing lists from several scalar expressions where the size of the resulting list should not change? I do. Quite a bit, actually. It is a natural thing to do in Perl. So things that return a scalar should return a scalar.

Doing the "right thing" in a case that matters and is natural is much more important to me than doing the "right thing" in a case that I find doesn't matter (because it is unnatural).

- tye        


In reply to Re^6: Module Announcement: Perl-Critic-1.01 ("right") by tye
in thread Module Announcement: Perl-Critic-1.01 by jthalhammer

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.