A Computer Program is a set of instructions for a computer to follow. Programs are written in Programming Languages. The written program is referred to as source code and is converted into a form that a computer can execute via another program, called an interpreter, translator, compiler, or assembler. Programs are also referred to as software, whereas the computer that executes them is called hardware. If the program is stored in a hardware device (such as in a read-only memory chip), the program/device combination is called firmware.
All useful work that a computer does is controlled by one or more programs, including the Operating System (O/S) which is a program that controls other programs. Other examples of programs: video games, Microsoft Word, Internet Explorer, and email viruses.
Nature of Programs
Programs are executed by the computer's CPU, and all source code must ultimately be translated into the machine code instructions for the CPU before it can be executed. Each instruction performs one specific small task in the CPU hardware. The CPU executes the instructions one at a time, from start to finish. Most instructions perform some operation on some data. For instance, an instruction may add two numbers together. Another instruction may output the result. The most powerful feature of computer programs is the ability to choose what instructions to execute based on a comparison of data. This conditional execution allows very complex programs to be written.
High-level programming languages, such as the [[BASIC Programming Language]], allow a programmer to write his program using higher-level concepts. A single statement in a programming language may translate into hundreds of machine code instructions. Most programs are therefore written using a high-level programming language and most programmers think in terms of the abstraction provided by that language.
There are five basic aspects of programs: data is information that is processed and/or generated by the program. Data includes text, numbers, measurements, and inputs to the program. algorithms are the steps to follow to accomplish a given task, which are implemented as a series of instructions. Also called routines. Algorithms operate on data. For instance, an algorithm may calculate the square-root of a number or count the number of letters in a word. I/O means Input/Output. Input is the process of taking data from outside the program, and output is when the program sends data to the user or stores it somewhere outside of the program (such as on a hard disk). Flow control is the ability to choose what code is executed. This involves changing the order in which instructions are executed. If the change is based on certain values of data, it is called conditional execution. When the same instructions are repeated it is referred to as a loop. Finally, subroutines are algorithms that are used in multiple places in the program but not in a way that can be made use of via a loop. Rather than include a copy of the algorithm at every place it is needed, it is included once and the program can make calls to the algorithm. All programs involve some combination of these five aspects of programs.
Bugs are flaws in programs that cause them to operate in a manner not intended by the programmer. The misbehavior may be serious or minor. The larger a program, the greater the chance of the existence of bugs, and the greater the number of different bugs. The quality of a program is sometimes measured in terms of lines of code per bug.
The speed of a program depends upon how many instructions are needed to accomplish its tasks, the speed of the CPU running the program, and the speed of the I/O. An inefficiently coded program takes more instructions to do a unit of work than an efficiently coded program, and will therefore run more slowly. However, inefficiency is sometimes purposely chosen if the inefficiency leads to a simpler implementation. Note that in a multi-tasking environment, such as Microsoft Windows, the speed of a program can also be affected by the execution of other programs.
A program can be viewed as the process of obtaining some data, performing operations on the data, and outputting the results. When combined with flow control, the program can monitor something's status, and appropriately respond to changes in that status. For instance, a word processing program (such as Microsoft Word) will wait for the user to type a character on the keyboard. This wait is a loop that continuously checks for a typed character. When the character is typed, the character becomes the data. The program will then perform some operations depending upon what character was typed. For instance, there may be an algorithm to automatically convert the character to uppercase if the user is positioned at the start of a sentence. This is conditional execution (if the character is a lowercase letter and at the start of a sentence). Next the program outputs the character (perhaps changed from the original data) to the screen where the user sees it. Finally, the program loops back to the start to wait for another character.