Functions - Definition

Most of the computer programs that solve real-world problems are much bigger and complex than the programs presented in the first few chapters. The existing software engineering practices used to develop such complicated programs work on the following principles:
  1. Top-down design, modularization, stepwise refinement and bottom-up development: According to this principle, a complex problem should be modularized (i.e. divided) into sub-problems that are simpler, manageable and easier to solve as compared to the original problem. If the divided sub-problems are still complex and cannot be easily solved, they are further divided into sub-problems. Each level of division provides a refinement and simplicity to the problem. This process of modularization is carried out till the sub-problems are simple enough and can be easily solved. The solutions for these simple problems are then developed and merged to provide a solution for the overall complex problem. This approach of problem solving is also known as 'divide-and-conquer strategy.' This strategy is practically followed in real life whereby a senior officer responsible for the execution of a work divides the work among his subordinates. The subordinate officers may further divide the assigned work among their subordinates, get the work done and report back to their senior officer. This hierarchical division of work is shown in Figure 1.

    Figure 1. Hierarchical division of work
    Thus, in this approach of solution development, a solution to the given problem is thought of at an abstract level. This abstract solution is divided into modules, and each level of division refines the solution by adding details to the divided modules. The process of division is carried out till the divided modules are well defined and simple enough to be generated (i.e. coded). The functionality of each module is kept in a separate function. These functions are relatively independent of each other and interact with each other to provide a solution to the overall problem.

  2. 'Don't reinvent the wheel.' Another important software engineering principle states that 'Don't reinvent the wheel.' This means that the functionality that has already been developed should be reused instead of being developed again. Functions help a lot in realizing this principle. The commonly required functionality is developed and kept in standard libraries for the use in the form of library functions. In the previous chapters, we have used the input and output functionality by using scanf and printf library functions. The C standard library provides a rich set of functionality for performing the common mathematical calculations, string and character manipulations, input/output and other useful operations.

Post a Comment

Previous Post Next Post