While I wish I could ++ this node more than once, I do have one nit.

I don't totally like using $str in both left hand and right hand sides of the assignment. While far short of what M.J. Dominus calls a red flag, the double appearance suggests that other coding mechanisms should be considered.

Perl does this in the core with uc and friends. I originally considered this to be a crufty legacy from the past (and it may be), but I have since found it to be a benefit.

My reasoning is simple - when I'm parsing something, I often want to keep the original unblemished and transform the original into a copy. While I can easily do something as assign it to a copy, I'm not always at liberty to be working with the absolute original copy. Sometimes, I, the caller of fraction(), am working with a partially-transformed version of the copy. By explicitly saying $str = fraction( $str );, I am telling my maintainer(s) what is going on without them having to read the code for fraction(). Simply saying convert_ratio_to_number( $str ); may not be explicit enough.

Now, this argument does not apply in the case of an object. Methods are assumed to have side-effects where functions are not.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose


In reply to Re: Code Clarity & Cost Analysis by dragonchild
in thread Call sub first or later by kiat

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.