PBBS16 Documentation

Modular Approach in Programming

Modular programming is the process of subdividing a computer program into separate sub-programs. A module is a separate software component. It can often be used in a variety of applications and functions with other components of the system.

UPDATE October 2021: I have recently learned, the IT industry has coined the phrase "Microservice" for this type of design. Which I guess means, CodeRunner is a Microservice Server. And the way I have been coding for 35 years, is making microservices... anyway, back to my original content:
  • Some programs might have thousands or millions of lines and to manage such programs it becomes quite difficult as there might be too many syntax errors or logical errors present in the program, so to manage such type of programs concept of modular programming approached.
  • Each sub-module contains something necessary to execute only one aspect of the desired functionality.
  • Modular programming emphasis on breaking of large programs into small problems to increase the maintainability, readability of the code and to make the program handy to make any changes in the future or to correct the errors.

Points which should be taken care of prior to modular program development:

  1. Limitations of each and every module should be decided.
  2. In which way a program is to be partitioned into different modules.
  3. Communication among different modules of the code for the proper execution of the entire program.

Advantages of Using Modular Programming Approach --

  1. Ease of Use: This approach allows simplicity, as rather than focusing on the entire thousands and millions of lines code in one go we can access it in the form of modules. This allows ease in debugging the code and prone to fewer errors.
  2. Reusability: It allows the user to reuse the functionality with a different interface without typing the whole program again.
  3. Ease of Maintenance: It helps in less collision at the time of working on modules, helping a team to work with proper collaboration while working on a large application.
C is called a structured programming language because to solve a large problem, C programming language divides the problem into smaller modules called functions or procedures each of which handles a particular responsibility. The program which solves the entire problem is a collection of such functions.

A module is basically a set of interrelated files that share their implementation details but hide it from the outside world. How can we implement modular programming in c? Each function defined in C by default is globally accessible. This can be done by including the header file in which the implementation of the function is defined.

Suppose, we want to declare a Stack data type and at the same time want to hide the implementation, including its data structure, from users. We can do this by first defining a public file called stack.h which contains generic data Stack data type and the functions which are supported by the stack data type.

In the header file, we must include only the definitions of constants, structures, variables and functions with the name of the module, which makes it easy to identify the source of definition in a larger program with many modules.

Pascal developers do not tend to structure their code where each module is a specific function only. However, PBBS does take a modular approach, and only a few of these include files contain more than one function (when it made sense).