I'm refactoring a piece of code that uses $x, $y, $z. There are 6 repetitions of a large chunk of code that are essencially identical, but for the 'ordering' of those three variables.
This is ripe for refactoring into a subroutine called 6 times. Ie:
if( $x ) { doStuff( $x, $y, $z ); doStuff( $x, $z, $y ); } if( $y ) { doStuff( $y, $x, $z ); doStuff( $y, $z, $x ); } if( $z ) { doStuff( $z, $x, $y ); doStuff( $z, $y, $x ); }
But here is a dilemma I've encountered many times before, what do you name the 3 variables inside the sub:
sub doStuff { my( $?, $?, $? ) = @_; .... }
I know it's trivial, just call'em $p, $q, $r or $u, $v, $w or $a, $b, $c I hear the collective mind screaming, but it is a large and fairly complex piece of code, and $x, $y, $z are actually placeholders for a bunch of different entities that have x, y & z components all interacting and it gets quite confusing -- here's one of the 6 blocks in the code I'm adapting:
So my question is, is there some technique or pattern or something that has been devised to deal with this? Have you arrived at some way of dealing with this situation that works for you?
In reply to Refactoring technique? by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |