Authors
Publication
Pub Details
Date
Pages
Part one of our step by step guide to help turn every one of you users out there into expert programmers.
Any programs written by beginners to computing show a lack of what professionals call structure. The structure of a program is the way in which it is put together and the order in which the code — the language in which it is written — is put down in the finished product.
This series will show the beginner how to structure programs so that they will work faster and occupy less memory. As an example of how the techniques work, a database will be constructed in the articles which can he used to store lists of information, such as names and addresses or telephone numbers. The information stored in the database can be called back by typing in a keyword which corresponds to the information sought by the user.
Before we start to do any coding it is important to know about flowcharting. A flowchart, such as the one in figure one, is constructed before coding to act as a guide to what the finished program will look like. If it is written after coding has been completed and before the programmer starts to search for errors — to debug the program — it will be an aid in finding redundant code or code which inhibits the flow of a program.
The program flow is the way in which the program will be executed It is important to have that correct or errors will continue to occur on the program and the speed of the program will be slower.
The basic flowcharting symbols are the Input/Output box, operation rectangle and decision diamond and an example of each is shown in figure one.
The I/O box is used to mark places where an entry is made by the computer operator, or when the computer displays data on a screen or printer. The box can be used for all forms of input including keyboard, joystick, or even punched cards on a large mainframe com* puter.
When debugging a program, checks for errors should first be made at those junctions in the flowchart as the boxes mark places where a user can crash a program by entering the incorrect information.
The decision diamond is the most complex operation box in a computer flowchart — and the most necessary. A computer is distinguished from other machines through its ability to make decisions based on information. Usually the processing of that information will provide a simple yes or no answer. The inflow to the diamond descends vertically and splits in two to provide the yes/no options.
The option which contradicts the program flow goes out to the side of the box and can be directed up, to form a loop until the action has been performed correctly, or down if alternative action is required to that of the normal flow.
Finally, the operation rectangle is used to show that the computer has to perform some kind of calculation, That may be adding numbers, assigning numbers to variables, or scanning a string of characters. The use of that and the other boxes is illustrated in figure one.
Flowcharts usually are constructed before writing a program but it is a good idea to draw up one From the finished program to see if the program flows as it was originally intended.
When drawing a chart the boxes should be balanced as much as possible to the left and right of the main stern of the flow. The whole point of flowcharting is to create an easily understood diagram. The labels inside the symbols should be written in English and not in Basic.
The diagram in figure one uses several decision diamonds and they branch to both left and right. A flow on just one side of the diagram looks sloppy if there are more than two decisions to be made.
The way not to structure a flowchart is shown in figure two. The flow lines at the side have been run together, making it almost impossible to decide what happens next. That is remedied easily by making the chart longer and restructuring the lines into separate boxes as shown in figure three.
When writing a program it is a good idea to draw several flow diagrams. The first would be an overall plan showing the sections of program to be written and subsequent diagrams would expand each box to show the flow of the various routines,
A program is structured in a similar way to a flowchart. Most programs are constructed in the way figure one shows, The technique is called modular programming because the structure is broken into subroutines, or sections, called modules.
The reason is to eliminate as many GOTO statements as possible, or to make a GOTO statement jump only to a part of the routine in which it is situated, i.e., to make what is termed a local jump, or the control routine at the top of the program.
The control routine consists of a series of GOSUBs. It is the part of the program which is used most so it is the first thing that the computer encounters when scanning the program. In that way the program is faster in execution so it becomes more efficient.
A control routine can have two distinct structures. The first is used in a game-type program. That type of program will execute routines by going down through each of the GOSUBs in turn and then returning to the beginning.
The other type of structure is that which we shall use for the database. The program will first jump to the menu routine where the user will select an option. Control is then sent back to the control routine and using a series of IF . , „ THEN statements, the program will go to the subroutine selected by the player. The control program will not go down through all the GOSUBs but jump only to those specified by the user through the menu.
The database will function using a keyboard recognition function. The user enters a few words which act as a key phrase. The program will then look through the list, or file, of information in the program and, if a match is made between the key phrase and part of a piece of information, that piece of information will be output. The computer will output all information which is associated with the key phrase.
The program wiil also have to support separate data files and be user- friendly so that anyone can use it. The program menu will have search files, and create new files. The program structure will look like this from top to bottom, with the control routine at the top.
The complete flowchart of the database is shown in figure one. Using that chart it will be easy to translate each operation into program code.
Next month I will show how the overall structure of the program is finalized and then we can start coding.