Structured+Programming

__ What is a well-designed program? __  A well designed program should be: · Modular - program code is divided into distinct logical blocks that can be altered or removed with minimal effect on the rest of the program. Procedures and functions should be used effectively to achieve this. · Use meaningful identifiers – variable names should be understandable by people other than the person who wrote it. · Generic – though good program code aims to have specific purposes, it should be written to be as reusable as possible. Therefore a balance needs to be considered when writing. An example might be a function to perform a task such as calculating an average. If the code is written so that it accepts data as arguments, it can be used in any situation to perform this task and is therefore reusable. If the function were just to calculate an average for a specific situation, this would not be generic. · Reliable – the code should be able to handle all situations or data without breaking. To achieve this testing must be undertaken. When appropriate tests have been passed, we can consider the code to be reliable. · Understandable – code should be written in a style which is readable and understandable to people other than the programmer who wrote it. This would mean constructing the code using meaningful identifiers, not overcomplicating the logic of the program, using indentation and writing suitable comments throughout. · Efficient – good programs should, whilst being understandable and not overcomplicated, should always seek to perform a task in the most efficient manner. Care should be taken not to make unnecessary use of resources, such as memory, CPU use or network bandwidth, as single programs may not have a noticeable footprint but when they are scaled up to be used on a large scale system, this footprint will increase greatly. · Maintainability – this is connected with the concepts of modularity and being generic. If these ideas are adhered to then programs should be maintainable, that is if changes are needed, they can be implemented without breaking the rest of the program. __ What is structured programming? __  Structured programming is a programming technique that allows for the construction of well-designed programs. It is a subset of “procedural” programming (modular programming using procedures) and is often confused with it. Structured programming uses several features to do this and is primarily concerned with avoiding the use of the “goto” statement and the use of global variables. These features are: · Selection: the use of IF THEN ELSE statements allows for logical flow in a program depending on the current state of the program. · Repetition: looping allows for the program to perform repetitive tasks until some condition is reached. · Use of parameters passed into procedures and functions to avoid the use of global variables. · A “chain of instructions” that has one direction. The program is ordered and flows from beginning to end. The GOTO statement should be avoided. · Top down design: the problem is broken down into smaller sections from the top down, rather than starting with the details and working upwards. Some design techniques to assist good program design with structured programming: · Structured English and stepwise refinement allow for “structure tables” which detail the program in a human readable form. · Pseudo code describes the program in a more detailed fashion which can be easily translated into programs in any programming language. It resembles program code but does not use features of any particular language. · Flow charts help programmers to design the structure of the program and visually represent areas where the flow is changed by selection statements or tasks are repeated using loops.