Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Refactoring Perl #7 - Remove Assignments to Parameters

by agianni (Hermit)
on Aug 24, 2007 at 12:51 UTC ( #634849=note: print w/ replies, xml ) Need Help??


in reply to Re: Refactoring Perl #7 - Remove Assignments to Parameters
in thread Refactoring Perl #7 - Remove Assignments to Parameters

Actually, I think the example code as it stands is in the spirit if not the word of what the refactoring pattern is meant to avoid. While $arg_ref is a local temp, it's still a reference to the original arguments (a hashref), so updating it would update the arguments pass, which is what this pattern is meant to address. Hence the introduction of the secondary temp. That said, for the sake of completeness, the completely un-refactored code might look like this as you suggest:

sub discount{ $_[0]->{input_val} -= $_[0]->{input_val} > 50 ? 2 : 0; $_[0]->{input_val} -= $_[0]->{quantity} > 100 ? 1 : 0; $_[0]->{input_val} -= $_[0]->{year_to_date} > 10000 ? 4 : 0; return $_[0]->{input_val}; }


Comment on Re^2: Refactoring Perl #7 - Remove Assignments to Parameters
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://634849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-28 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (180 votes), past polls