Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Refactoring technique?

by BrowserUk (Patriarch)
on Apr 24, 2015 at 13:56 UTC ( [id://1124534]=note: print w/replies, xml ) Need Help??


in reply to Re: Refactoring technique?
in thread Refactoring technique?

Not sure what your question is. Just naming of parameters?

Yes & no. Imagine you're the programmer charged with looking at this code (see the spoiler) a couple of years from now, and you're trying to make sense of $text1, $text2, & $text3 in context.

If they have specific roles, find a name corresponding to that role.

Again, take a look at the code in spoiler. Can you see a "name corresponding to that role"? <P.Or for a better sense of the scale of the problem:

  • look at the original code;
  • find the function called _BoundingBoxDraw();
  • and then look for the 6 blocks that begin with the line:<code>gg=_GetGrid( ... );</c>

The 3 parameters need to be substituted everywhere that x, y, or z are used within that block, but sometimes the first parameter will be the x component of all the things; sometimes the y; sometimes the z; and so on for the other two parameters.

Within the context of 3D code x, y, z give some sense of what the thing you're dealing with is; text1, text2, text3 don't.

Similarly, for u, v, w; but it's worse, because you intuitively think of them as being placeholders for x, y, z respectively, but they aren't. Or rather sometimes they will be but mostly they will be some other ordering.

Similarly, if you use numbers -- say $xyz1, $xyz2, $xyz3 -- we tend to associate them to some ordering, even though we know that any one of the formal parameters could be any one of the actual parameters.

Its just something that has recurringly given me pause for thought each time I've encountered it down the years and I've never really come up with a good solution/approach to the problem.


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

Replies are listed 'Best First'.
Re^3: Refactoring technique?
by hdb (Monsignor) on Apr 24, 2015 at 16:18 UTC

    Now I got you. For my education (I have never used js), how do you parameterize x, y and z anyway. You have a lot of something.x and somethingelse.y. If you would want to write doStuff( u, v) how would you use u and v in the code?

      how do you parameterize x, y and z anyway. You have a lot of something.x and somethingelse.y.

      I'm still getting to that, but it seems that in JS, any place you can write o.x you can also write o['x'], so, I'm hoping that by extension, instead of:

      function doStuff( x, y, z ) { ... oo.x.thing = p.y.max * qq.z.min; ... }

      I can also write:

      function doStuff( a, b, c ) { ... oo[a].thing = pp[b].max * qq[c].min; ... }

      I'm still cleaning up and refactoring other parts, so I haven't tried that yet; but from what I read, and a couple of small tests, I think it will work.

      If any JS guys are following along and can verify that (or not), I'd be grateful.


      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

        Lucky for you that want the oo[a] notation instead of oo.x notation. I am mostly positive that Javascript cannot interpolate a method call at runtime. Consider the following:

        #!/usr/bin/node var key = 'id'; var obj = { id: 123, key: "wrong key!" }; function do_meth( obj, key ) { return obj.key; } function do_windex( obj, key ) { return obj[key]; } console.log( do_meth( obj, key ) ); console.log( do_windex( obj, key ) );
        When run, do_meth returns "wrong key!" instead of 123. You have to hard code return obj.id ... or use bracket notation such as you desire.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        

        I have been meditating over your original code. I cannot say what it does but the generalstructure looks like this: there are three sections, one for each plane. I would call that parameter $plane. In each of the three sections, there are three subsections: some prep stuff involving the two other directions in the same way and then two sections that you seem to want to refactor into doStuff. Each section needs both other directions but starts dealing with one of them first. For example, in tge z plane section it first deals with the x axis, then with the y axis. I would therefore call one direction $primary and the other $secondary. So in summary it would be doStuff( $plane, $primary, $secondary ).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found