Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Creating Variables Just to Pass into Subroutine?

by hexcoder (Curate)
on Jul 21, 2015 at 21:34 UTC ( [id://1135719]=note: print w/replies, xml ) Need Help??


in reply to Creating Variables Just to Pass into Subroutine?

Hello,

refactoring inherited code can be scary, unless you have a good set of tests for all the use cases the code needs to handle. Think of it as a safety net before you start. Also, a version control system would be useful in case of unintentional destructive changes...

So this should be the foundation to build on and the first step.

Once you have that, I would start refactoring with the help of Damian Conways' book 'Perl best practices' and the Perl-Critic tool. Keep the amount of changes small and focused, and retest often. Always before checking into version control.

Regarding your code snippet: assigning one variable to another one at least has the benefit of having more meaningful variable names (which makes it more user friendly, but is a bit redundant). Why not use good names in the first place?

Passing subroutine parameters in a hash, where the keys name the parameters, can also yield readable code, since the names are part of the subroutine interface then.

I hope this helps a bit.

  • Comment on Re: Creating Variables Just to Pass into Subroutine?

Replies are listed 'Best First'.
Re^2: Creating Variables Just to Pass into Subroutine?
by mdskrzypczyk (Novice) on Jul 22, 2015 at 13:38 UTC
    It helps a lot thanks for the reply, I've asked my higher up to prepare a set of test cases for the typical files that will be flowing through the automation for me so that I could make incremental changes and test that the functionality is still the same. I will look into version control, the problem is that these automation files are on a separate server and I'm required to work on windows...so I sftp the files to my work computer and then sftp them back after making changes. Do you have a suggestion on how I could get the version control somehow in here? Also my concern is that version control puts the files online and I'm not sure if the company would be okay with potentially confidential information being stored online...

      Don't use a server on the internet for your repo?
      Just run the service locally.

      The only thing you'll be missing is the off-site storage, and your IT department can handle that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2024-04-25 05:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found