in reply to Code Clarity & Cost Analysis
in thread Call sub first or later

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