Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Program structure: subs vs modules vs Selfloader

by matija (Priest)
on Jun 20, 2004 at 15:05 UTC ( #368288=note: print w/replies, xml ) Need Help??

in reply to Program structure: subs vs modules vs Selfloader

You are asking the wrong questions:

If the 200 line routine seems messy now, do you think it will be any better in a separate module? Perhaps you could refactor it into several routines, and make it more readable in the process?

How big is the rest of the program? If it's 200 lines of the subroutine and five lines of the rest, does it really make sense to create a module just for the routine (it might, if you think other people (or you at another time) might have a use for that subroutine). If it's a 200 line subroutine in a 1000 line program, it will probably make sense to break it into modules - and probably more than one.

Unless the module was very general, breaking the program into a tiny script and a large module does not improve readability.

Self loader, of course, does NOTHING for readability - it might improve loading times, sometimes. However, you need to know what you're doing, and I suggest a thorough course of benchmarking to make sure the added complication of Selfloader really is offset by the reduced code size on initial load. It is no way a foregone conclusion.

  • Comment on Re: Program structure: subs vs modules vs Selfloader

Replies are listed 'Best First'.
Re^2: Program structure: subs vs modules vs Selfloader
by bradcathey (Prior) on Jun 20, 2004 at 17:23 UTC
    Good points matija, thanks. For the record, my main program is only about 400 lines and, per your point, it will not be called by other scripts. It was the thought of having a "large" sub load everytime that got me to thinking. But may it is much to do about nothing, since neither are really huge. I guess I was asking as a matter of principle, especially if I ever do have a large script with subs.

    "Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-12-02 15:56 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (43 votes). Check out past polls.