Structured programming is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Certain languages such as Ada, Pascal, and dBASE are designed with features that encourage or enforce a logical program structure.
Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or set of similar functions is coded in a separate module or submodule, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure.
Program flow follows a simple hierarchical model that employs looping constructs such as "for," "repeat," and "while." Use of the "Go To" statement is discouraged.
Structured programming was first suggested by Corrado Bohm and Guiseppe Jacopini. The two mathematicians demonstrated that any computer program can be written with just three structures: decisions, sequences, and loops. Edsger Dijkstra's subsequent article, Go To Statement Considered Harmful was instrumental in the trend towards structured programming. The most common methodology employed was developed by Dijkstra. In this model (which is often considered to be synonymous with structured programming, although other models exist) the developer separates programs into subsections that each have only one point of access and one point of exit.
Almost any language can use structured programming techniques to avoid common pitfalls of unstructured languages. Unstructured programming must rely upon the discipline of the developer to avoid structural problems, and as a consequence may result in poorly organized programs. Most modern procedural languages include features that encourage structured programming. Object-oriented programming (OOP) can be thought of as a type of structured programming, uses structured programming techniques for program flow, and adds more structure for data to the model.
Modular Programming
Modular programming can be used to break up a large program into manageable units, or to create code that can be easily re-used. A modular program consists of a main module and one or more auxiliary modules. Each module originates from a separate source code file. The main module is compiled as an EXE, and calls functions in the auxiliary modules. The auxiliary modules can be dynamically linked, meaning they exist as separate executable files (DLLs) which are loaded when the main EXE is run; or they can be statically linked, meaning they are compiled as object files or static libraries (LIBs) that are combined with the main module into a single executable file.
Once you have learned how to create an executable file from an XBasic source program, it is easy to extend the procedure to make dynamically linked modules and (a little less easily) statically linked modules. There are, however, a few rules that must be followed when writing the source code for the auxiliary modules.
Each module must have a unique name, assigned in the PROGRAM statement. This name must be the same as the file name of the source code, minus the .x extension. For example, the source code auxiliary.x must have the statement PROGRAM "auxiliary" in the PROLOG. (The standard PROLOG code contains the comment that the program name must have 1 to 8 characters, but names longer than this seem to work without any problem. However, the name cannot contain spaces.)
Function names need to be unique across all modules (with the exception of INTERNAL FUNCTIONs). This includes the Entry() function, which will need to be renamed in each auxiliary module. After re-naming the Entr
Answered by
Deepak
at
5:05 PM on December 20, 2008