|
|||||||||||||||||
|
Lesson #1 - Top Down DesignLast updated: Mon Feb 18 09:27:28 PST 2002 Programs are best thought of as a list of instructions, which can be seen group together by purpose. At the very top level, you might have: BEGIN DO 'program'; END. This is just a reference to another set of instructions. BEGIN & END note where your program runs from and too, marking off a block of instructions that you could denote at a higher level as one item. From here, we could expand on the 'program' instruction: DEFINE 'program' BEGIN DO 'get data input by user'; DO 'manipulate data'; DO 'display data as output'; END; BEGIN DO 'program'; END. The three stages of the 'program' module listed here are also the key stages of any program. They will all occur in a real program at least once, in one way or another (although you might not realize it sometimes). You could write a program that leaves out some of the steps, but it would be mostly useless. For purposes of simplification, you could reduce the program to this: DEFINE 'get data input by user' BEGIN END; DEFINE 'manipulate data' BEGIN END; DEFINE 'display data as output' BEGIN END; BEGIN DO 'get data input by user'; DO 'manipulate data'; DO 'display data as output'; END. In this now, our actual instructions are just empty blocks, they do nothing. We could thusly simplify them further. Notice the semi-colon at the end of the line, that tells the system this is the end of an instruction definition. DEFINE 'get data input by user'; DEFINE 'manipulate data'; DEFINE 'display data as output'; These are called prototypes in many programming languages, because they just tell the system that a certain instruction exists, without giving details about the function. To answer a question a received about my examples here, what I call instructions are known by several other names in various programming languages. These include sub-routines (Basic), procedures (Pascal) and functions (C/C++ & Pascal).
© 1999-2013 Robin Johnson
all works, in any form, remain the property of their respective owners content may not be reproduced without the explicit permission of the author |