Chapter 04 Procedural Abstraction - Function
1. General Description
When people design a complex program, they usually uses the method of function decomposition and function mix.
- Function decomposition refers to designing a program in a top-down and step-wise way, which means dividing a large goal into several smaller ones and dividing these smaller ones into some tiny ones if possible until we can solve the problem easily.
- Function mix refers to apply the outcome of each atomic problems to finally get to the initial goal in a bottom-up way.
In the process of decomposition and mix, we need a system of abstraction, such as procedural abstraction and functional abstraction, which indicates that we don’t have to know clearly how to do it in the every beginning, we just need to know what to do and what we’d like to achieve.
2. Sub-Program
2.1 What is Sub-program?
Sub-program is a block of code that has its unique name and in the program, where these code is need will be placed the name. And this practice will help us avoid repeating many unnecessary codes as well as accomplishing procedural abstraction.
In addition to procedural abstraction, sub-program also plays a role of encapsulation and information hiding.
2.2 Data Transfer Between Sub-programs
When defining a function, we need to set its parameters and when making a function call, we need to input some arguments according to its parameters, in which process we transfer data to the function and get a return value.
The most elementary two ways are call-by-value and call-by-reference, the latter one is more faster and efficient but will have some side effects.