Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Refactor huge subroutine

by grep (Monsignor)
on Aug 13, 2008 at 04:03 UTC ( #704031=note: print w/replies, xml ) Need Help??

in reply to Refactor huge subroutine

A couple of comments:

Those labels look like a good place to start. sub them out and pass the array.

Those large, gnarly if/elsif clauses would be my next step. Create a descriptively named sub like has_many_valid_lodgements, move the logic there and return true or false. This also has the advantage of self-documenting your code. No one will be able to quickly discern what

scalar(@all_lodgements) > 2 && ($total_all_lodged == $total_qcs_docs)

Look for copy-and-paste code like the Date_Cmp's. Get rid of them. Make 1 sub and name it well.

Other Notes:

  • Think about writing tests, even with the code as it stands. The tests for this will have to be high level but you'll know if you break something (or even find a bug). As you refactor add smaller tests for the smaller components. It not only will keep you from breaking things, it helps you think about refactoring. Refactored code is generally easily tested.
  • Think about self documenting the code. You seem to use decent variable names continue that with the refactored subs. Think about leaving your code to someone else, and if they'll like you in the end :)
One dead unjugged rabbit fish later...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2020-05-25 08:29 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (144 votes). Check out past polls.