Idea to Execution
Life Cycle of a Program
How does a program become a program? And what does a computer actually do when it “runs” a program? Let’s take a peek under the hood and examine the process of how an idea gets turned into a dynamic, interactive program running on your computer.
It all starts with an idea. Well, actually, it starts with a problem that necessitates a solution that then gives rise to the idea for how to solve the problem.
Smart problem solvers begin the process of turning an idea into something real by first analyzing the problem at hand. They ask questions, collect information, gather data, look at existing solutions, and think through the situation as thoroughly as they can before diving into a solution.
It might seem difficult to restrain yourself when you are struck with a brilliant idea. But the best ideas are almost never the first ones that come up. Remember the encryption exercise. Most students could intuitively come up with the Caesar cipher all on their own, but that proves to be one of the least robust solutions to that problem.
In practice, the first idea to come to mind is almost always an inferior solution. But with careful thought, consideration, and analysis of the idea’s strengths and weaknesses, a good designer will always come up with something better than their first instinct. So, avoid those kneejerk reactions to initial ideas and look for the better idea. It’s out there. You just need to make the effort to seek it out.
Construct an Algorithm
Once a developer has identified a solution that is worth pursuing, the next step is to begin turning it into a well-specified plan of action.
As we’ve seen earlier in this unit, computer scientists—whether they are programmers writing code or designers developing algorithms—apply their computational thinking skills to the process of mapping out a logical sequence of instructions that will solve the problem. They recognize and use the sequencing, selection, and iteration patterns we’ve looked at in the past. They anticipate and identify all of the unseen and unexpected complications that their solution will need to encounter. And they clearly define the requirements, expectations, and specifications for how the resulting program should perform.
Write the Code
Once the program specifications have been clearly defined and all algorithms have been constructed, a programmer then implements the algorithm in a formal programming language (i.e., writes the code at an appropriate high-level or low-level programming language).
These days, most software is developed in a high-level language that takes advantage of the benefits of abstraction in making the final code simpler and more straightforward for humans to understand, while still remaining formal and strict enough for a machine to read and parse. A wealth of development tools are available to help programmers more easily manage large programs that combine large numbers of smaller algorithms and operations. Both Scratch and Processing, which you will work with in the next few units, provide an easy-to-use, graphical interface with which to develop, test, and run your programs.
Smart programmers also design thorough test cases to verify that all aspects of their program perform as intended. Sometimes the design of the algorithm is flawed, leading to a program that misperforms. Other times, the algorithm is sound, but the program fails to accurately implement it in the chosen programming language. Either way, it is important that these bugs (i.e., errors) in the program are identified and corrected before the software is distributed to end-users.
Compile the Code
The programs that programmers write in high-level languages are known as source code. Technically, these source code files are not really programs, per se. They are the abstract, high-level instructions that define what the program is and how it will function. The actual program—that is, the file containing the machine-level instructions the computer actually runs—is written in special binary (1s and 0s) patterns that relate directly to the way the computer’s processor has been designed and wired. This binary, machine code is a direct, low-level translation from the high-level source code.
Fortunately, the programmer does not have to personally perform this tedious translation. Instead, it can be automated in a process called compilation. This basically means that your program can be translated by another program! During the compilation process, another program, called the compiler, translates each of your high-level, human-readable instructions into a corresponding string of 1s and 0s that make sense to the computer’s processor. The resulting string of binary information constitutes an executable program.
Execute the Compiled Code
When a user wants to run, or execute, a program, all of the instructions and raw data that make up that program are loaded into memory (i.e., RAM). That is, the binary, machine code is copied from wherever it is stored in secondary storage (e.g., hard drive, USB drive, etc.) into primary storage (e.g., RAM).
0, respectively. Each circuit in RAM is, thus, capable of storing 1 bit (from the abbreviation of “**b**inary dig**it*”) of information. For perspective, 1 gigabyte (1 GB) of RAM consists of more than 8.5 trillion bits.
Once a program’s binary contents have been copied into RAM, the computer’s central processing unit (CPU) begins reading each of the binary instructions bit-by-bit, byte-by-byte, word-by-word as it executes each instruction in the sequence that the code/algorithm specifies.
As it does so, each instruction or operation causes various electronic components to be activated throughout the computer. Some of these operations change the values stored in RAM. Others read and calculate new values based on information stored in RAM. Still others draw images, symbols, or text onto the screen; capture user input from a mouse, keyboard, or touchscreen; send data to a printer; play music and sound effects; or any number of other types of basic computational functionality.
The sum total of all of these discrete operations is what the end user recognizes as a properly functioning program, whether it is a web browser, a word processor, a game, a streaming media player, or whatever else it was that the original idea that started this process was intended to do.