A computer program is a sequence of instructions[1] that can be executed by a computer to perform a specific task.
A computer program is usually written by a computer programmer in a programming language. From the program in its human-readable form of source code, a compiler or assembler can derive machine code—a form consisting of instructions that the computer can directly execute. Alternatively, a computer program may be executed with the aid of an interpreter.
A collection of computer programs, libraries, and related data are referred to as software. Computer programs may be categorized along functional lines, such as applications software and system software. The underlying method used for calculation or manipulation is known as an algorithm. Functional programming may be achieved by organizing memory into data structures.
The earliest programmable machines preceded the invention of the digital computer. As early as the 9th century, a programmable music sequencer was invented by the Persian Banu Musa brothers, who described an automated mechanical flute player in the Book of Ingenious Devices.[2] In 1206, the Arab engineer Al-Jazari invented a programmable drum machine where musical mechanical automata could be made to play different rhythms and drum patterns.[3]
Blaise Pascal built the Pascaline in 1643 -- an adding machine for his father who was a tax collector in France. The brass box had six dials, each with ten notches. When a dial completed a revolution, it moved the next dial one place. A series of numbers could be entered, and a cumulative sum obtained.[4] The Pascaline was an analog computer in that it computed by measuring distance.[5]
In 1801, Joseph-Marie Jacquard devised a loom that would weave a pattern by following a series of perforated cards. Patterns could be woven and repeated by arranging the cards.[6]
In 1837, Charles Babbage was inspired by Jacquard's loom to attempt to build the Analytical Engine.[6] The names of the components of the calculating device were borrowed from the textile industry. In the textile industry, yarn was brought from the store to be milled. The device would have had a "store"—memory to hold 1,000 numbers of 40 decimal digits each. Numbers from the "store" would then have then been transferred to the "mill" (analogous to the CPU of a modern machine), for processing. A "thread" is the execution of programmed instructions by the device. It was programmed using two sets of perforated cards—one to direct the operation and the other for the input variables.[6] [7] However, after more than 17,000 pounds of the British government's money, the thousands of cogged wheels and gears never fully worked together.[8]
During a nine-month period in 1842–43, Ada Lovelace translated the memoir of Italian mathematician Luigi Menabrea. The memoir covered the Analytical Engine. The translation contained Note G which completely detailed a method for calculating Bernoulli numbers using the Analytical Engine. This note is recognized by some historians as the world's first written computer program.[9]
In 1936, Alan Turing introduced the Universal Turing machine—a theoretical device that can model every computation that can be performed on a Turing complete computing machine.[10] It is a finite-state machine that has an infinitely long read/write tape. The machine can move the tape back and forth, changing its contents as it performs an algorithm. The machine starts in the initial state, goes through a sequence of steps, and halts when it encounters the halt state.[11] This machine is considered by some to be the origin of the stored-program computer—used by John von Neumann (1946) for the "Electronic Computing Instrument" that now bears the von Neumann architecture name.[12]
The Z3 computer, invented by Konrad Zuse (1941) in Germany, was a digital and programmable computer.[13] The Z3 contained 2,400 relays to create the circuits. The circuits provided a binary, floating-point, nine-instruction computer. Programming the Z3 was through a specially designed keyboard and punched tape.
The Electronic Numerical Integrator And Computer (ENIAC) was built between July 1943 and Fall 1945. It was a Turing complete, general-purpose computer that used 17,468 vacuum tubes to create the circuits. At its core, it was a series of Pascalines wired together.[14] Its 40 units weighed 30 tons, occupied 1,800 square feet (167 m2), and consumed $650 per hour (in 1940s currency) in electricity when idle.[14] It had 20 base-10 accumulators. Programming the ENIAC took up to two months.[14] Three function tables were on wheels and needed to be rolled to fixed function panels. Function tables were connected to function panels using heavy black cables. Each function table had 728 rotating knobs. Programming the ENIAC also involved setting some of the 3,000 switches. Debugging a program took a week.[14] The programmers of the ENIAC were women who were known collectively as the "ENIAC girls"[15] and included Jean Jennings Bartik, Betty Holberton, Marlyn Wescoff, Kathleen McNulty, Ruth Teitelbaum, and Frances Spence. [16] It ran from 1947 until 1955 at Aberdeen Proving Ground, calculating hydrogen bomb parameters, predicting weather patterns, and producing firing tables to aim artillery guns.[17]
Computers manufactured until the 1970s had front-panel switches for programming. The computer program was written on paper for reference. An instruction was represented by a configuration of on/off settings. After setting the configuration, an execute button was pressed. This process was then repeated. Computer programs also were manually input via paper tape or punched cards. After the medium was loaded, the starting address was set via switches, and the execute button was pressed.[18]
In 1961, the Burroughs B5000 was built specifically to be programmed in the ALGOL 60 language. The hardware featured circuits to ease the compile phase.[19]
In 1964, the IBM System/360 was a line of six computers each having the same instruction set architecture. The Model 30 was the smallest and least expensive. Customers could upgrade and retain the same application software.[20] Each System/360 model featured multiprogramming. With operating system support, multiple programs could be in memory at once. When one was waiting for input/output, another could compute. Each model also could emulate other computers. Customers could upgrade to the System/360 and retain their IBM 7094 or IBM 1401 application software.[20]
Computer programming is the process of writing or editing source code. Editing source code involves testing, analyzing, refining, and sometimes coordinating with other programmers on a jointly developed program. A person who practices this skill is referred to as a computer programmer, software developer, and sometimes coder.
The sometimes lengthy process of computer programming is usually referred to as software development. The term software engineering is becoming popular as the process is seen as an engineering discipline.
Computer programs can be categorized by the programming language paradigm used to produce them. Two of the main paradigms are imperative and declarative.
Imperative programming languages specify a sequential algorithm using declarations, expressions, and statements:[21]
var x: integer; 2 + 2 yields 4x := 2 + 2; if x = 4 then do_something();One criticism of imperative languages is the side effect of an assignment statement on a class of variables called non-local variables.[22]
Declarative programming languages describe what computation should be performed and not how to compute it. Declarative programs omit the control flow and are considered sets of instructions. Two broad categories of declarative languages are functional languages and logical languages. The principle behind functional languages (like Haskell) is to not allow side effects, which makes it easier to reason about programs like mathematical functions.[22] The principle behind logical languages (like Prolog) is to define the problem to be solved – the goal – and leave the detailed solution to the Prolog system itself.[23] The goal is defined by providing a list of subgoals. Then each subgoal is defined by further providing a list of its subgoals, etc. If a path of subgoals fails to find a solution, then that subgoal is backtracked and another path is systematically attempted.
A computer program in the form of a human-readable, computer programming language is called source code. Source code may be converted into an executable image by a compiler or assembler, or executed immediately with the aid of an interpreter.
Compilers are used to translate source code from a programming language into either object code or machine code.[24] Object code needs further processing to become machine code, and machine code consists of the central processing unit's native instructions, ready for execution. Compiled computer programs are commonly referred to as executables, binary images, or simply as binaries – a reference to the binary file format used to store the executable code.
Some compiled and assembled object programs need to be combined as modules with a linker utility in order to produce an executable program.
Interpreters are used to execute source code from a programming language line-by-line. The interpreter decodes each statement and performs its behavior. One advantage of interpreters is that they can easily be extended to an interactive session. The programmer is presented with a prompt, and individual lines of code are typed in and performed immediately.
The main disadvantage of interpreters is computer programs run slower than when compiled. Interpreting code is slower because the interpreter must decode each statement and then perform it. However, software development may be faster using an interpreter because testing is immediate when the compiling step is omitted. Another disadvantage of interpreters is an interpreter must be present on the executing computer. By contrast, compiled computer programs need no compiler present during execution.
Just in time compilers pre-compile computer programs just before execution. For example, the Java virtual machine Hotspot contains a Just In Time Compiler which selectively compiles Java bytecode into machine code – but only code which Hotspot predicts is likely to be used many times.
Either compiled or interpreted programs might be executed in a batch process without human interaction. Scripting languages are often used to create batch processes. One common scripting language is Unix shell, and its executing environment is called the command-line interface.
No properties of a programming language require it to be exclusively compiled or exclusively interpreted. The categorization usually reflects the most popular method of language execution. For example, Java is thought of as an interpreted language and C a compiled language, despite the existence of Java compilers and C interpreters.
Typically, computer programs are stored in non-volatile memory until requested either directly or indirectly to be executed by the computer user. Upon such a request, the program is loaded into random-access memory, by a computer program called an operating system, where it can be accessed directly by the central processor. The central processor then executes ("runs") the program, instruction by instruction, until termination. A program in execution is called a process.[25] Termination is either by normal self-termination, by user intervention, or by error – software or hardware error.
Many operating systems support multitasking which enables many computer programs to appear to run simultaneously on one computer. Operating systems may run multiple programs through process scheduling – a software mechanism to switch the CPU among processes often so users can interact with each program while it runs.[26] Within hardware, modern day multiprocessor computers or computers with multicore processors may run multiple programs.[27]
Computer programs may be categorized along functional lines. The main functional categories are application software and system software. System software includes the operating system which couples computer hardware with application software.[28] The purpose of the operating system is to provide an environment in which application software executes in a convenient and efficient manner.[28] In addition to the operating system, system software includes embedded programs, boot programs, and micro programs. Application software designed for end users have a user interface. Application software not designed for the end user includes middleware, which couples one application with another. Application software also includes utility programs. The distinction between system software and application software is under debate.
Application software is the key to unlocking the potential of the computer system.[29] Enterprise application software bundle accounting, personnel, customer, and vendor applications. Examples include enterprise resource planning, customer relationship management, and supply chain management software.
Enterprise applications may be developed in house as a one-of-a-kind proprietary software.[29] Alternatively, they may be purchased as off-the-shelf software. Purchased software may be modified to provide custom software. If the application is customized, then either the company's resources are used or the resources are outsourced. Outsourced software development may be from the original software vendor or a third-party developer.[29]
The advantages of proprietary software are features and reports may be exact to specification.[30] Management may also be involved in the development process and offer a level of control. Management may decide to counteract a competitor's new initiative or implement a customer or supplier requirement. A merger or acquisition will necessitate enterprise software changes.[30]
The disadvantages of proprietary software are the time and resource costs may be extensive.[30] Furthermore, risks concerning features and performance may be looming.
The advantages of off-the-shelf software are its identifiable upfront costs, the basic needs should be fulfilled, and its performance and reliability have a track record.[30]
The disadvantages of off-the-shelf software are it may have unnecessary features that confuse the end users, it may lack features the enterprise needs, and the data flow may not match the enterprise's work processes.[30]
One approach to economically obtaining a customized enterprise application is through an application service provider.[31] Specialty companies provide the hardware, custom software, and end-user support. They may speed development of new applications because they possess skilled information system staff. The biggest advantage is it frees in-house resources from staffing and managing complex computer projects.[31]
Many providers target small, fast-growing companies with limited information system resources.[31] On the other hand, larger companies with major systems likely have their technical infrastructure in place. One key risk is having to trust an external organization with sensitive information. Another key risk is having to trust the provider's infrastructure reliability.[31]
Other application software categories are:
Example of an app: GCalctool, a software calculator
Utility programs are designed to aid system administration and software execution. Operating systems execute hardware utility programs to check the status of disk drives, memory, speakers, and printers.[32] A utility program may optimize the placement of a file on a crowded disk. System utility programs monitor hardware and network performance. When a metric is outside an acceptable range, a trigger alert is generated.[33]
A software developer may embed a compression program so a data file is stored on less disk space.[32] An administrator may compress a data file before it is transmitted over the network to save time. End users may select to have a utility program sort or merge a data set.[33] A personal computer may have virus detection installed.
An operating system is the low-level software that supports a computer's basic functions, such as scheduling tasks and controlling peripherals. [28]
In the 1950s, the programmer, who was also the operator, would write a program and run it. After the program finished executing, the output may have been printed, or it may have been punched onto paper tape or cards for later processing.[18] More often than not the program did not work. The programmer then looked at the console lights and fiddled with the console switches. If less fortunate, a memory printout was made for further study. In the 1960s, programmers reduced the amount of wasted time by automating the operator's job. A program called an operating system was kept in the computer at all times.[34]
Originally, operating systems were programmed in assembly; however, modern operating systems are typically written in higher level languages like C, C++, Objective-C, Swift, and Java (UI).
A stored-program computer requires an initial computer program stored in its read-only memory to boot. The boot process is to identify and initialize all aspects of the system, from processor registers to device controllers to memory contents.[35] Following the initialization process, this initial computer program loads the operating system and sets the program counter to begin normal operations.
Independent of the host computer, a hardware device might have embedded firmware to control its operation. Firmware is used when the computer program is rarely or never expected to change, or when the program must not be lost when the power is off.[34]
The microcode program is the bottom level interpreter that controls the data path of software driven computers.[36] (Advances in hardware have migrated these operations to hardware execution circuits.)[36] Microcode instructions allow the programmer to more easily implement the digital logic level[37] -- the computer's real hardware. The digital logic level is the boundary between computer science and computer engineering.[38]
A gate is a tiny transistor that can return one of two signals -- on or off.[39] Having one transistor forms the NOT gate. Connecting two transistors in series forms the NAND gate. Connecting two transistors in parallel forms the NOR gate. Connecting a NOT gate to a NAND gate forms an AND gate. Connecting a NOT gate to a NOR gate forms an OR gate. These five gates form the building blocks of binary algebra -- the digital logic functions of the computer.
Microcode instructions are mnemonics programmers may use to execute digital logic functions instead of forming them in binary algebra. They are stored in a central processing unit's (CPU) control store.[40] These hardware-level instructions move data throughout the data path.
Microcode instructions move data between a CPU's registers and throughout the motherboard. The micro-instruction cycle begins when the microsequencer uses its microprogram counter to fetch the next machine instruction from main memory.[41] The next step is to decode the machine instruction by selecting the proper output line to the hardware module.[42] The final step is to execute the instruction using the hardware module's set of gates.
Instructions to perform arithmetic are passed through an arithmetic logic unit (ALU).[43] The ALU has circuits to perform elementary operations to add, shift, and compare integers. By combining and looping the elementary operations through the ALU, the CPU performs its complex arithmetic.
Microcode instructions move data between the CPU and the memory controller. Memory controller microcode instructions manipulate two registers. The memory address register is used to access each memory cell's address. The memory data register is used to set and read each cell's contents.[44]
Microcode instructions move data between the CPU and the many computer buses. The disk controller bus writes to and reads from the hard disk drives. Data is also moved between the CPU and other functional units via the peripheral component interconnect express bus.[45]