1. Nothing to add but an example: select FH uses this, since one often wants to re-select the originally selected file handle.

  2. I don't buy the rationale you gave for this method. The caller should not have to do integrity checks. The rationale for this one is probably for consistency with $b = $a = $val.

    This method is also useful when you want to provide a single method for setting and getting. For example, $cypher->iv($iv); and $iv = $cypher->iv();.

  3. This method can improve readability. A common alternative is a constructor that accepts a list (or a reference to a hash) of options.

However, I beg to differ on their ability to indicate success. None of these are particulary good at indicating success, because none of these are particulary good at indicating failure.
  1. Without limiting the values that can be used as parameters, the return value cannot be used to indicate failure. Some other means of indicating failure (such as exceptions) is necessary.

  2. Checking for failure entails check checking if the return value is different than the parameter's value. This could entail having to use a temporary variable, and checking if two things are equal can be very tricky depending on what kind of things make accesptable parameter. In short, some other means of indicating success (such as exceptions) would be preferable.

  3. In this case, a false value could be returned on failure, but that would cancel out the entire benefit of this method. If the function can return undef, one can no longer chain calls, since one would have to check the return value. It would be safer to just return 1 for success and undef for failure.


In reply to Re: 'Set' Method Return Value by ikegami
in thread 'Set' Method Return Value by jdhedden

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.