in reply to Lots of subs in large program vs lots of small programs

I would suggest writing it this time as a large program with a bunch of subroutines, BUT try to group your subroutines together in a logical fashion with clear separators between the sections that you come up with. Try to make each function make sense on its own, and limit how much functions in each section call functions in the other sections.

There are several reasons that I suggest this. The most important is that recognizing design elements requires some experience. If you are not in the habit of writing modules, then you probably lack that skill and can spend a lot of time thrashing about without making much progress. However you probably can more easily write functions and after the fact recognize somewhat natural divisions. Focussing on writing loosely coupled functions will make it likely that natural divisions can more easily be recognized. If the result turns out well, you can then try moving some of those sections into modules after the fact.

The process of trying to reflect on the result afterwards should help develop some of the design skills that you will need in the future to modularize up front. But not facing that in addition to everything else that you change will make the first attempt more likely to succeed.

Or so goes my theory... (Good luck!)

  • Comment on Re: Lots of subs in large program vs lots of small programs

Replies are listed 'Best First'.
Re: Re: Lots of subs in large program vs lots of small programs
by Roger (Parson) on Oct 31, 2003 at 05:34 UTC
    tilly's comments ++. I just want to add my personal experience here -

    I find that the easiest way to decide what should be a subroutine and what should be a separate module is by drawing a system diagram.

    First determine the logical functional units that the system is composed of. Then draw a system diagram that shows the interaction between logical function blocks. A diagram is better than a thousand words. Before I proceed on a large project, I always draw lots of system diagrams and flowcharts to help me visulize the system. Design deficiencies can be spotted quite easily.

    Rule of thumb for designing a good system:

    1) Minimum cohesion. Design your functional blocks so that they have minimum cohesion between them. In other words, minimise interaction between modules at the same level.
    2) What the subroutine does can be described by one sentense with out the word 'and' or 'or'... In other words, a clearly defined single task for each subroutine.
    3) Keep the size of a module to less than a few pageful.

    There are plenty of good references and books on good software design practise. I find the following link on software design quality management quite interesting.