Download: 2.1.3 Procedural Thinking
- Being able to identify the key components (parts) of the problem.
- Being able to devise/identify the components needed for the solution.
- Identifying what sub-programs (modules, such as functions & procedures) are needed.
- Determining the order of steps are needed. This is order of execution. One module may need to process data first in order to be used by another module. It is important to understand that some modules may need to be accessed in unpredictable ways.
Problem Decomposition: (Breaking down a complex problem or system into smaller parts that are more manageable & easier to understand.) / (Break a complicated task into a set of identifiable subtasks.)
- This involves dividing a large & complex problem into smaller sub-problems & splitting these problems further until each problem can be solved. These sub-problems might then be able to be developed as programmable modules (functions/procedures)
- Decomposition allows the smaller sub-problems to be easily solved compared to having one larger and more complex problem. This is because larger problems are daunting. Abstraction can help with this process. The smallest type of sub-problem/task is called ‘atomic’.
- This allows divide & conquer to be used.
- This can also increase the speed of production in programming.
- This can also reduce the amount of active processing & memory requirements.
- This is good in teamwork as programmers can be assigned to areas that match their specialties. However, this can introduce errors if each subprogram/module cannot interact correctly.
Composition: (Combing objects or data types into more complex ones.)
- Combining the atomic procedures, which were created from solving smaller-sub problems, to generate a complex structure.
- For example, assemble the modules. Each sub-program will produce a result, which then the output of one module will become the input to the next one.
Modules: (Functions / Procedures)
- Modules are basically created as separate ‘mini programs’. There are blocks of code that sit outside of the main program.
- These modules are then called from the main program when required.
- Modules inspire teamwork. This is because coding each procedure or function can be allocated to different team members depending on their specialties.
- ‘Declaring’ a module means writing the modular code. It is given a name, which is called the header. The body of the module contains instructions, which are a series of code.
- ‘Calling a module’ means naming the module in the main program. The commands stored in the function / procedure are carried out. They carry out in the order you call them. If the module is never called, the code inside the module is never used/executed.
- Good thing about modular programming is that it doesn’t matter what order you make the procedures or what order they are spawn in the code. The sequence of modules is set by the main program. They are carried out in the order they are called.
- Procedures & Functions made by other programmers can be used. This is called a ‘code library’. There are imported into your program. After you import the code library (another word is module), then you can use all the stored procedures/functions in your code.
Advantages of Modular Programming:
- Breaks a large and complex program down into small & manageable parts.
- It allows you to save a block of code, which can be used again and again. This includes being used in future programs.
- It makes programs shorter as it can get rid of repeated code.
- They can make a program more readable depending on the module’s name.
- Work can be allocated between team members.
- It causes less risk of the program breaking / not working as your program can use tried & tested procedures & functions.
- It allows programmers to share their modules via importing procedures / functions made by other programmers.
541 total views, 1 views today