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?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Refactoring technique? by BrowserUk

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.