In modular programming approach, the program is progressively decomposed into smaller partitions called modules. The programs can be easily written in modular form, thus allowing an overall problem to be decomposed into a sequence of individual sub-problems. Thus, we can consider a module decomposed into successively subordinate module. Conversely, a number of modules can be combined together to form a superior module.
Sub-modules are located elsewhere in the program and the superior module, whenever necessary, make a reference to subordinate module and call for its execution. This activity on the part of the superior module is known as calling, and this module is referred as calling module and sub module referred to as ‘called module’.
The sub-modules maybe Â sub-programs such as functions or procedures. For example, if a program need initial and boundary conditions, sub-routines are used to set them. Then if someone else wants to compute a different solution using that program , only these sub-routines need to be changed. This is a lot easier than having to read through a program line by line, trying to figure out what each line is supposed to do and whether it needs to be changed. The values passed to the sub-routine are arguements and the variables defined in the sub-routine are parameters. Further, arguments show exactly what information a sub-program is using. That makes it easier to figure out whether it needs to be changed when we are modifying our program. Forgetting to change all occurrences of a variable is a very common source of errors.
Sub-programs make it simpler to figure out how the program operates. If the boundary conditions are implemented using a sub-routine, the program can be searched for this subroutine to find all places where the boundary conditions are used. This might include some unexpected places, such as in the output, or in performing a numerical check on the overall accuracy of the program.
Sub-programs reduce the likelihood of bugs. Because sub-programs can use local variables, there is less chance that the code in the sub-routine interferes with that of the program itself, or with that in other sub-programs. The smaller size of the individual modules also makes it easier to understand the global effects of changing a variable.
Modular approach provides following advantages-
1.COMPLEXITY: Probably the most important reason to produce a module is to reduce the complexity of the problem. By sub dividing the problem into a number of modules,we can hide the information not needed outside the module, and then only concentrate on the specifics of the module inside. If this is still complex, then sub-modules should be created.
2. DUPLICATION: Avoiding duplicate code is a reason for using modules. The basic fact that the code is in one place means it is easier to maintain, save space, and reduce the complexity and hence reliability of a program.
3. DEBUGGING: By isolating areas, debugging becomes easier and reliable because we are working with smaller section of thenprogram. Things like hardware dependencies, operating system dependencies, input/output dependencies, laws and business rules, and complex data structures and complex logic are some of the ideal candidates.
4. PERFORMANCE: We can also use modules to create improved performance. Â We can optimize or recode in a limited amount of modules (that are ‘hot-spots’) rather than trying to improve the efficiency of the whole code.
5. HIDING DATA STRUCTURES: The hiding of data structures, and their use, in modules, form a good use for modules. Complex data structures tend to be very tangled and difficult to understand things and their physical use doesn’t really translate very well to the problem domain. Therefore the best way to avoid complexity when using these structures is to make modules that do the work, and then call these.
6. HIDING GLOBAL DATA: Global data can also be hidden in modules. That means we can monitor access to the data if necessary, and change the structure of the data without changing the whole program. Quite often putting access to the data in a module means we can find that the data can become local or module level.
7. RE-USABILITY: Modules can be used in other programs without rewriting rewriting or retesting. This reusability is a very important characteristic of modules.
8. READABILITY: Programs are more readable because of the modular structure. A readable module is worth a lot, simply because someone might need to understand it to upgrade or remove a bug. We should never underestimate readability.
9. PORTABILITY: By isolating non-portable sections of code in modules, we can make it easier to move the program to other machines. Such sections include hardware dependencies and operating system dependencies. There are two levels of porting-
- Porting to a machine with the same processor- Porting to a machine having the same processor is a matter of re-coding the OS differences.
- Porting to a machine with a different processor- Porting to a machine having a different processor involves re-coding the hardware and OS differences.
10. DEVELOPMENT WORK: Several programmers can work on different modules of a large program relatively independent of one another. Each module can also be tested separately from the rest of the program.
TO READ MORE ABOUT COMPUTER ENGINEERING, VISIT- Engineering Community