The top-down design approach G
OOD DAY, students. This is lesson 25 in our series of lessons. In this week’s lesson, we will look at modularity/top-down design and programming languages (the beginning of a new unit).
USE OF THE TOP-DOWN DESIGN APPROACH TO PROBLEM SOLVING
You have learnt in previous lessons the way in which you solve a problem on the computer, and you have been learning thus far how to write your pseudocodes and how to construct your flow charts. Now you are going to learn about a technique that can be employed when you have a big program to code or problem to solve. This method is called the ‘top-down design approach to programming’.
WHAT IS TOP-DOWN DESIGN?
The top-down design approach or modular programming, as it is sometimes called, involves breaking a problem into a set of smaller problems, called subproblems or modules, followed by breaking each subproblem into a set of tasks. This is called a divide-and-conquer approach. When faced with a complex problem, it is easier to break the problem down into smaller, more manageable sections and tackle each section as a separate entity, rather than trying to solve the large problem in one go.
Let’s assume you were creating a program to simulate the basic operations of a calculator. Below is a diagram depicting a typical top-down design or modularity approach to programming for the calculator scenario.
As you may observe with the diagram above, there is a major problem which has been broken down into two subproblems. The subproblems are then broken down into respective tasks of which certain specific action(s) will be carried out.
A subproblem is a set of related tasks. A task is a set of related actions. An action is a basic instruction that needs no further refinement. For example, an action might be a simple instruction such as subtract two numbers. The process of dividing the problem into subproblems, or modules, and breaking them down into smaller units is called stepwise refinement.
One advantage of modular programming is that when a problem has been decomposed into smaller subproblems, each subproblem can be solved as a single entity. However, the solution of each individual subproblem does not necessarily solve the larger problem. There must be cohesion between the modules. That is, there must be a mechanism for communicating between the different subproblems.
PROGRAMMING LANGUAGES
Programming languages fall into the following categories: 1. Machine language – categorised as a 1st generation language. 2. Assembly language – categorised as a 2nd generation language. 3. High Level language – categorised as a 3rd generation language. 4. Fourth-Generation language. These languages can be further categorised as either being low-level or high-level languages.
LOW LEVEL
Machine language. Assembly language.
HIGH LEVEL
High-level language. Fourth-Generation language. Let us now examine each of these languages.
MACHINE LANGUAGE
This was the first language available for programming. At the machine level, the instructions are written in ones and zeroes (binary digits). This is the only language that the computer understands.
ADVANTAGES
Programs execute fast. Efficient use of memory.
DISADVANTAGES
Programming is slow and tedious. Code is difficult to learn, read, understand and correct. Code is machine specific; that is, it cannot be used in the same form on other computer models.
ASSEMBLY LANGUAGE
This was developed to replace the zeroes and ones of machine language with symbols that are easier to understand and remember. It uses special codes called mnemonics (words that suggest meaning) to represent machine language instructions.
An assembly language is translated into a machine language by using a translator program called an assembler. However, both the machine language and assembly language programs are machine dependent, i.e., the way the program is written depends on the operation of the computer.
ADVANTAGES
Programming is faster and less tedious than for machine language.
Code is easier to learn, read and understand than for machine language.
Execution is faster than high-level languages.
DISADVANTAGES
Programming is slower and more tedious than high-level languages.
Code is machine-specific.
HIGH-LEVEL LANGUAGES
These differ from low-level languages in that they require less coding details and make programs easier to write. They are closer in appearance to natural language, for example, English and French. Programs written in high-level language are called source code, while the translated version is called object code. These programs must be translated to a form which can be accepted by the computer. This is achieved by means of special translator programs called compiler and interpreter.
In contrast to a compiler, an interpreter does not translate the whole program prior to execution. Rather, it translates the code, line by line, during the execution of the program. With the compiler, all the translation is done and then the object program is executed. They are not machine dependent. Examples of highlevel language are Basic (Beginners All-Purpose Symbolic Instruction Code), Pascal (which is the programming language you will learn for CSEC), COBOL (Common Business-Oriented Language), JAVA, C Programming, and so on.
ADVANTAGES
Programming is faster and less tedious. Code is easier to learn, read, understand and correct. Language is more English and math like.
DISADVANTAGE
Program executes slowly.
FOURTH GENERATION
They are often describe as very high-level languages and referred to as 4GLs. They are easyto-learn, easy-to-use languages that enable users or programmers to code applications much more quickly than they could with lower-level languages. Two examples of 4GLs are DBASE and FOXPRO.
ADVANTAGE
Useful for generating reports.
DISADVANTAGE
Can be very wordy.
We have come to the end of this lesson. See you next week, when we will look at some key programming terms and the Pascal language. Remember, if you fail to prepare, you prepare to fail.