FLOWCHARTSFew people create programs overnight. Instead, most programs evolve over time. 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 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. 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. 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. Ultimately, no one cares what language you use as long as your 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 mile radius, your pseudocode may look as follows:. In the preceding example, you can see that each pseudocode instruction needs further refining before you can start writing your program. You can refine the instructions even further to specify how the computer works in more detail, as follows:. Make sure that the target coordinates are valid: 1 Make sure that the target coordinates are complete. 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 Technical Details of Writing a Program. About the Book Author Wallace Wang is a bestselling author with more than 2. He's also a stand-up comic who has performed on TV.
The Technical Details of Writing a Program
For getting the turtle to draw simple things, like a box, you can just enter Logo instructions in TG's CommandCenter and most of the time your program just works. It does what you wanted it to, what you thought it would do. However, when you write any non-trivial program, this will rarely be the case. The more instructions you include in your programs, the more you need to keep in your head, in your working memory, about what you're doing. The more instructions, the more typing you will do; so, the more chances or a typo. And finally, the more instructions, the more chances to make a mistake. A third step is the conversion of the pseudocode into properly formed instructions that are available in the programming language you are using, Logo in our case. When you did the exercises at the end of the last lessonmy guess is that you didn't type in programs that worked perfectly the first time. If you did, congratulations The good news is that anyone can learn to write correct programs - an experienced programmer would have no problem writing "correct" programs for these exercises. An experienced programmer would think about how to solve the problem before she would start typing in instructions. An experienced programmer would break the problem into pieces that each are simple to do by themselves. Then, put all the pieces together to solve the problem. In computer science this is a process that's called " stepwise refinement. What you should do first is think about what you need to do. Get out some paper and a pencil to write down your thoughts. Look at the diagram carefully. You need to get the turtle to: draw thirteen line segments six horizontal and seven vertical. Start at a corner and just walk the turtle around, forward, backward, right turn, left turn, until all the line segments are painted. So you now have some sketches and notes on a piece of paper that describe ways that lead to a solution. The next step is to decide on an approach and put together instructions, a processa procedurewhich gets the turtle to draw the figure. Let's follow our experienced programmer's thoughts through the rest of a solution. She has chosen to draw a square a special kind of rectangle and subdivide it. Her first step: figure out how many turtle steps each side of the square should be. Since it will be split in half and into thirds, she wants a length that is a multiple of two and three. As you can see, it's nice to know a little bit of math when you're programming a computer. Most beginning programmers would not have thought about the size as a first step. So if this caught you by surprise, no big deal. You would have found out that it is important when you were further along. But it is important for you to know the level of detail that an experienced programmer considers, that you will eventually think about when you write big programs. With this decided, the experienced programmer first writes her program down on paper in pseudocode. Pseudocode is jargon for describing something in your native language. Her pseudocode is English descriptions of what she wants her program to do. Once this is complete and she is convinced that her plan should produce what she wants, it's time for the next phase: converting the pseudocode into Logo instructions. Time to convert the plan into a program that can be executed on a computer.
Know the common loop structures, branching structures, and mathematical operator symbols to make your program perform specific instructions. Comment your program liberally. Write modular programs by dividing a large program into several smaller programs that you isolate from one another. Test boundary conditions by giving your program extremely high and extremely low numbers. Make your program work first; then worry about optimizing the program to make it smaller and faster. Looping instructions, one of the basic logic structures in computer programming, tell the computer to repeat one or more instructions. Check out this list of basic loop structures in various computer programs and languages:. Branching structures make your computer programs run different instructions depending on the value of specific data. Branching structures, like the ones listed below, allow your computer to run more effectively by accepting and reacting to outside data. In computer programming, four basic ways are used to manipulate numbers: adding, subtracting, multiplying, and dividing. To perform a mathematical operation with two numbers or two numbers represented by variablesuse these symbols in your computer program:. Cheat Sheet. Use appropriate data types. Write programs that are easy to read and understand. Use simple algorithms and data structures whenever possible. Common Computer Programming Loop Structures Looping instructions, one of the basic logic structures in computer programming, tell the computer to repeat one or more instructions. Common Branching Structures in Computer Programming Branching structures make your computer programs run different instructions depending on the value of specific data. Common Mathematical Operators Used in Programming In computer programming, four basic ways are used to manipulate numbers: adding, subtracting, multiplying, and dividing. About the Book Author Wallace Wang is a bestselling author with more than 2. He's also a stand-up comic who has performed on TV.