Programming
Award-winning computer designer and engineer W. Daniel Hillis captured the essence of programming when he said: "The magic of a computer lies in its ability to become almost anything you can imagine, as long as you can explain exactly what that is. The hitch is in explaining exactly what you want. With the right programming a computer can become a theater, a musical instrument, a reference book, a chess opponent. No other entity in the world except a human being has such an adaptable, universal nature."
Computer programming has many facets: It is like engineering because computer programs must be carefully designed to be reliable and inexpensive to maintain. It is an art because good programs require that the programmer use intuition and a personal sense of style. It is a literary effort because programs must be understood by computers, and this requires mastery of a programming language. That is not all—programs must be analyzed to understand how they work and usually must be modified periodically to accommodate changing requirements. Therefore, as programs are written, programmers should care about how elegant they are, and they should understand how they arrived at the solution of a problem.
Techniques
Telling a computer what to do is not as easy as it sounds. Every detail of the computer's desired operation must be precisely described, and plans must be made for all possible occurrences. For example, if a store has a billing program set up to send monthly bills to all customers, then the computer will send out a bill for __BODY__ to those who owe nothing. If one tells a computer to send a threatening letter to customers who have not paid, then those who owe nothing will receive menacing letters until they send in payments of __BODY__! Avoiding this kind of mix-up is one aspect of computer programming. The programmer's art is stating exactly what is desired. In this example, it means making a distinction between customers who have not sent any money because they do not owe anything, and those who actually still owe money.
A combination of thorough problem definition and straightforward programming techniques lead to precise and effective programs. Therefore, programmers should observe the following steps:
- Define the problem exactly, because this constitutes about 80 percent of the difficulty of programming;
- Design the program simply because simple programs are easier to develop and maintain, and they result in more reliable, secure, robust, and efficient code;
- Execute the program with different sets of data. If possible, test the program by hand with just one input; this is a great way to find bugs, and is easy to use and understand.
The task of writing a computer program requires great attention to detail. Computers demand absolute completeness and precision in their instructions: they do only what they are told and their instructions cannot contain any ambiguity. This is true of all software. It applies equally to a simple program that makes a computer play a tune and to a huge program that monitors traffic at an airport.
In programming, nothing can be left to chance. Non-programmers tend to forget that actions they take for granted must be spelled out in great detail for the machine. Every action must be broken down into its most elementary parts to produce an algorithm. No detail, however self-evident to the human mind, can be omitted or taken for granted in a computer program. A good programmer must be capable of thinking about the big-picture that generates useful algorithms, and paying attention to the details that convert those algorithms into unambiguous computer code.
In its simplest form, an algorithm is like a recipe, but a computer programmer must specify extra steps that a cook would usually skip over. For example, a recipe might call for two eggs, without specifying that the eggs must be fresh, uncooked, and added to the mixture without the shell. If such criteria were assumed and not detailed precisely in a computer program, the recipe would fail. When hundreds or thousands of instructions covering every contingency have to be spelled out for the computer, expense naturally rises and bugs creep in.
There are several ways programmers can approach the problem systematically. Two of them are flowcharts and pseudocode. A flowchart is a graphic representation of the algorithm using standard symbols that can then be translated into computer language instructions. Pseudocode involves refining the problem in several stages starting with English sentences, which are then restated in subsequent steps with more computer-like words and statements.
Structured Programming
Structured programming, championed in 1968 by Dutch computer scientist Edsger W. Dijkstra, has exerted a major influence on the development of software ranging from small personal computer programs to multimillion-dollar defense projects. Only three control structures are required to turn out useful structured programs:
- Simple sequencing or instructing the computer to do one thing after another;
- Looping, or telling the computer to perform the same set of instructions while a condition holds or until a condition is met;
- Decision making, or enabling the computer's ability to branch in one of two directions depending on the outcome of a condition.
In addition, structured programs are typically divided into modules, which each perform one function, and do it well. The algorithms are easy to follow because there is only one logic entry into each module and one logic exit from it. Since the modules are small, usually not exceeding one page of code, they are easy to debug.
Programmers
A programmer's goal is not to solve a problem but to map out instructions that will let the computer find the solution. Performing rapid calculations is a job tailor-made for a computer, but designing the step-by-step algorithm that tells the computer exactly how to proceed with a given assignment is better left to human intelligence. To make the algorithm as clear as possible, a programmer always starts by assembling the known facts and setting out a clear statement of the problem. Then the programmer begins devising a logical progression of steps for the computer to follow en route to the solution. Often the programmer will use an extreme version of the problem just to see if the logic of the algorithm holds up. This test often discovers missing steps or inaccurate instructions that would cause the computer to flash error messages.
Finally, the programmer has to consider the types of data the computer will be handling and decide on the best method for storing and retrieving the data for processing. By making the right decision regarding language, logic, and programming techniques, programmers can harness the power of the computer with maximum effectiveness.
The computer programmer is the link between a problem and its computer solution. Good programmers write well-structured and clear programs that others can read and modify. Writing good programs requires creativity, but it must be tempered with great patience and intense discipline so
that the resulting programs will be correct and efficient.
Bibliography
Bentley, Jon. Programming Pearls, 2nd ed. Reading, MA: Addison-Wesley, 2000.
Hillis, W. Daniel. The Pattern on the Stone. New York: Basic Books, 1998.
Time-Life Books. Understanding Computers: Software. Alexandria, VA: Time-Life Books, 1986.
ambiguity the quality of doubtfulness or uncertainty; often subject to multiple interpretations