rah,

It really depends. Asking if 200 lines is too much is kinda like asking is 200 coins too much. It all depends. Do you have 200 pennies, 200 quarters or 200 gold pieces, or a nice mixture? 200 lines means really nothing. When you're looking at those two hundred lines, ask yourself these questions:

How many of them are exact copies?
How many of them are similar copies?

What you want to do here is figure out how much "copy-n-paste" re-use you have - those are prime canidates for refactoring into subroutines.

Once you have the "copy-n-paste" out of the way. Take a look at what's left and ask your self these questions about each subroutine in term (and don't forget the implicit main subroutine).

Is this beastie cohesive - does it do one thing very well or is it all over the place
Is this beastie coupled - does it depend on global data or does it poke at other subroutine's data.

Shoot for high cohesiveness and low coupling (the holy grail of programming). The great thing about looking at cohesiveness and coupling at the functional level is that it can really help you refactor code into an OO level - hmmm this set of five methods work on this one data structure while this set of 3 work on another - eureka ... module discovery.

Now once you've done all that, your 200 lines of code may now be 300 lines of code - is that any worse? Well from a run-time perspective - probably. Calling subroutines or loading modules and calling methods cost you. But that cost is hopefully down in the noise and what you really gain is ease of maintainence and ease of extending when new batch jobs come along.

-derby


In reply to Re: Style Question: small and modular, or big enough to do the job in one piece? by derby
in thread Style Question: small and modular, or big enough to do the job in one piece? by rah

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.