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

Re: Perl archeology: Need help in refactoring of old Perl code that does not use strict

by AnomalousMonk (Archbishop)
on Nov 14, 2017 at 07:20 UTC ( [id://1203333]=note: print w/replies, xml ) Need Help??


in reply to Perl archeology: Need help in refactoring of old Perl code that does not use strict

I'd like to suggest that you also need a

Step 0: Write a test suite that the current code passes for all normal modes of operation and for all failure modes.
With this test suite, you can be reasonably certain that refactored code isn't just going to be spreading the devastation.

Given that you seem to be describing a spaghetti-coded application with communication from function to function via all kinds of secret tunnels and spooky-action-at-a-distance global variables, I'd say you have a job on your hands just with Step 0. But you've already taken a test suite into consideration... Right?


Give a man a fish:  <%-{-{-{-<

  • Comment on Re: Perl archeology: Need help in refactoring of old Perl code that does not use strict
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl archeology: Need help in refactoring of old Perl code that does not use strict
by Monk::Thomas (Friar) on Nov 14, 2017 at 12:14 UTC

    This is what I would do after 'Step 0':

    • identify a function using a global variable.
    • verify the global variable does not change during execution of this function, e.g. some other function called by this function modifies it. (insert some code to do this for you)
    • convert global variable into an argument and update all callers.

    If the variable does change during the run then pick a different function first. When you got the global state disentangled a bit it's a lot easier to reason about what this code is doing. Everything that's still using a global needs to be treated with very careful attention.

Re^2: Perl archeology: Need help in refactoring of old Perl code that does not use strict
by likbez (Sexton) on Nov 14, 2017 at 18:04 UTC
    Thank you. In this case we already have a set of test cases that can be compared and supposedly they cover all or or most of the branches.

    I am reading "Perl Medic: Transforming Legacy Code" hoping to understand this problem better, and it does contain this recommendation.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found