Few people create programs overnight. Instead, most programs evolve over time. Because the process of actually typing programming commands can prove so tedious, time-consuming, and error-prone, programmers try to avoid actually writing their programs until they're absolutely sure that they know what they're doing.
Prototyping
To make sure that they don't spend months (or years) writing a program that doesn't work right or that solves the wrong problem, programmers often prototype their programs first. Just as architects often build cardboard or plastic models of skyscrapers before a construction crew starts welding I-beams together, programmers create mock-ups (prototypes) of their programs first.
A prototype usually shows the user interface of the program, such as windows, pull-down menus, and dialog boxes. The prototype may look like an actual program, but clicking menus doesn't do anything. The whole idea of the prototype is to show what the program looks like and how it acts, without taking the time to write commands to make the program actually work.
After the programmer is happy with the way the prototype looks, he or she can proceed, using the prototype as a guideline toward completing the final program.
Many programmers use RAD languages like Visual Basic to create prototypes quickly. After you use Visual Basic to create a prototype that shows how your user interface works, you can start adding actual commands to later turn your prototype into an honest-to-goodness working program.
Choosing a programming language
After you refine your prototype until it shows you exactly how your program will look and act, the next step is choosing a programming language to use.
You can write any program by using any programming language. The trick is that some languages make writing certain types of programs easier than others.
The choice of a programming language to use can pit people against one another in much the same way that religion and politics do. Although you can't find a single "perfect" programming language to use for all occasions, you may want to consider a variety of programming languages. Ultimately, no one cares what language you use as long as your program works.
Defining how the program should work
After choosing a specific programming language, don't start typing commands into your computer just yet. Just as programmers create mock-ups (prototypes) of their program's user interface, they often create mock-up instructions that describe exactly how a program works. These mock-up instructions are known as pseudocode.
If you need to write a program that guides a nuclear missile to another city to wipe out all signs of life within a 100-mile radius, your pseudocode may look as follows:
1. Get the target's coordinates.
2. Get the missile's current coordinates.
3. Calculate a trajectory so the missile hits the target.
4. Detonate the nuclear warhead.
By using pseudocode, you can detect flaws in your logic before you start writing your program — places where the logic behind your program gets buried beneath the complexity of a specific programming language's syntax.
In the preceding example, you can see that each pseudocode instruction needs further refining before you can start writing your program. You can't just tell a computer, "Get the target's coordinates," because the computer wants to know, "Exactly how do I get the target's coordinates?" So rewriting the preceding pseudocode may look as follows:
1. Get the target's coordinates.
• Have a missile technician type the target coordinates.
• Make sure that the target coordinates are valid.
• Store the target coordinates in memory.
2. Get the missile's current coordinates.
3. Calculate a trajectory so the missile hits the target.
4. Detonate the nuclear warhead.
You can refine the instructions even further to specify how the computer works in more detail, as follows:
1. Get the target's coordinates.
• a. Have a missile technician type the target coordinates.
• b. Make sure that the target coordinates are valid: 1) Make sure that the target coordinates are complete. 2) Check to make sure that the target coordinates are within the missile's range. 3) Make sure that the target coordinates don't accidentally aim the missile at friendly territories.
• c. Store the target coordinates in memory.
2. Get the missile's current coordinates.
3. Calculate a trajectory so the missile hits the target.
4. Detonate the nuclear warhead.
When programmers define the general tasks that a program needs to accomplish and then refine each step in greater detail, they say that they're doing a top-down design. In other words, they start at the top (with the general tasks that the program needs to do) and then work their way down, defining each task in greater detail until the pseudocode describes every possible step that the computer must go through.
Writing pseudocode can prove to be time-consuming. But the alternative is to start writing a program with no planning whatsoever, which is like hopping in your car and driving north and then wondering why you never seem to wind up in Florida.
Pseudocode is a tool that you can use to outline the structure of your program so that you can see all the possible data that the computer needs to accomplish a given task. The idea is to use English (or whatever language you understand best) to describe the computer's step-by-step actions so that you can use the pseudocode as a map for writing the actual program in whatever language (C/C++, FORTRAN, Pascal, Java, and so on) that you choose.
dummies
Source:http://www.dummies.com/how-to/content/the-technical-details-of-writing-a-program.html
No comments:
Post a Comment