Computer program - Wikipedia

In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret.[1] In declarative programming, a computer program is a set of instructions.

A computer program in its human-readable form is called source code. Source code needs another computer program to execute because computers can only execute their native machine instructions. Therefore, source code may be translated to machine instructions using the language's compiler. (Machine language programs are translated using an assembler.) The resulting file is called an executable. Alternatively, source code may execute within the language's interpreter. The programming language Java compiles into an a intermediate form which is then executed by a Java interpreter.[2]

If the executable is requested for execution, then the operating system loads it into memory and starts a process.[3] The central processing unit will soon switch to this process so it can fetch, decode, and then execute each machine instruction.[4]

If the source code is requested for execution, then the operating system loads the corresponding interpreter into memory and starts a process. The interpreter then loads the source code into memory to translate and execute each statement.[2] Running the source code is slower than running an executable. Moreover, the interpreter must be installed on the computer.

In 1837, Charles Babbage was inspired by Jacquard's loom to attempt to build the Analytical Engine.[5] 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 had a "store" which was memory to hold 1,000 numbers of 40 decimal digits each. Numbers from the "store" were transferred to the "mill" for processing. It was programmed using two sets of perforated cards. One set to direct the operation and the other for the input variables.[5] [6] However, after more than 17,000 pounds of the British government's money, the thousands of cogged wheels and gears never fully worked together.[7]

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.[8]

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.[9] 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.[10]

The Z3 computer, invented by Konrad Zuse (1941), was a digital and programmable computer.[11] Zuse became aware of the "Babbage Engine" in 1939 while attempting to file a German patent.[11] Babbage's machine was base-10 — which was easy to comprehend. Zuse recognized that a binary machine was easy to construct. Telephone relays are two-position switches — open or closed. The Z3 had approximately 2,600 relays: 1,800 for the memory, 600 for the arithmetic, and 200 for the punch tape reader, keyboard, and display.[11] The circuits provided a floating-point, nine-instruction computer. Programming the Z3 was through a specially designed keyboard and punch tape. Manual input was through a calculator-style keyboard that accepted decimal numbers. The machine converted the input to binary and passed them through a series of calculating modules.[7] The result was converted back to decimal and displayed on an output panel.[11]

Simultaneously developed was its successor — the Z4 computer. (An air-raid on April 6, 1945 destroyed the Z3.) In 1950, the Z4 was placed into production at the Federal Technical Institute in Zurich. It pioneered the short tenure of relay-based computers.[11]

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.[12] 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.[12] It had 20 base-10 accumulators. Programming the ENIAC took up to two months.[12] 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.[13] 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.[14]

Instead of plugging in cords and turning switches, a stored-program computer loads its instructions into memory just like it loads its data into memory.[15] As a result, the computer could be programmed quickly and perform calculations at very fast speeds.[16] Presper Eckert and John Mauchly built the ENIAC. The two engineers introduced the stored-program concept in a three-page memo dated February 1944.[17] Later, in September 1944, Dr. John von Neumann began working on the ENIAC project. On June 30, 1945, von Neumann published the First Draft of a Report on the EDVAC which equated the structures of the computer with the structures of the human brain.[16] The design became known as the von Neumann architecture. The architecture was simultaneously deployed in the constructions of the EDVAC and EDSAC computers in 1949.[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] The Model 75 was the most premium. Each System/360 model featured multiprogramming[20] — having multiple processes in memory at once. When one process was waiting for input/output, another could compute.

IBM planned for each model to be programmed using PL/1.[21] A committee was formed that included COBOL, Fortran and ALGOL programmers. The purpose was to develop a language that was comprehensive, easy to use, extendible, and would replace Cobol and Fortran.[21] The result was a large and complex language that took a long time to compile.[22]

Switches for manual input on a Data General Nova 3, manufactured in the mid-1970s

Computers manufactured until the 1970s had front-panel switches for programming.[23] 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.[23]

Computer programming (also known as software development and software engineering) is the process of writing or editing source code. In a formal environment, a systems analyst will gather information from managers about all the business processes to automate. This professional then prepares a detailed plan for the new or modified system.[24] The plan is analogous to an architect's blueprint.[24] A computer programmer is a specialist responsible for writing or modifying the source code to implement the detailed plan.[24]

A programming language is a set of keywords, symbols, identifiers, and rules by which programmers can communicate instructions to the computer.[25] They follow a set of rules called a syntax.[25]

Programming languages get their basis from formal languages.[26] The purpose of defining a solution in terms of its formal language is to generate an algorithm to solve the underlining problem.[26] An algorithm is a sequence of simple instructions that solve a problem.[27]

The evolution of programming languages began when the EDSAC (1949) used the first stored computer program in its von Neumann architecture.[28] Programming the EDSAC was in the first generation of programming languages.

Imperative languages specify a sequential algorithm using declarations, expressions, and statements:[37]

FORTRAN (1958) was unveiled as "The IBM Mathematical FORmula TRANslating system." It first compiled correctly in 1958.[39] It was designed for scientific calculations, without string handling facilities. Along with declarations, expressions and statements, it supported:

However, non IBM vendors also wrote Fortran compilers, but with a syntax that would likely fail IBM's compiler.[39] The American National Standards Institute (ANSI) developed the first Fortran standard in 1966. In 1978, Fortran 77 became the standard until 1991. Fortran 90 supports:

COBOL (1959) stands for "COmmon Business Oriented Language." Fortran manipulated symbols. It was soon realized that symbols didn't need to be numbers, so strings were introduced.[40] The US Department of Defense influenced COBOL's development, with Grace Hopper being a major contributor. The statements were English-like and verbose. The goal was to design a language so managers could read the programs. However, the lack of structured statements hindered this goal.[41]

COBOL's development was tightly controlled, so dialects didn't emerge to require ANSI standards. As a consequence, it wasn't changed for 25 years until 1974. The 1990s version did make consequential changes like object-oriented programming.[41]

ALGOL (1960) stands for "ALGOrithmic Language." It had a profound influence on programming language design.[42] Emerging from a committee of European and American programming language experts, it used standard mathematical notation and had a readable structured design. Algol was first to define its syntax using the Backus–Naur form.[42] This led to syntax-directed compilers. It added features like:

Algol's direct descendants include Pascal, Modula-2, Ada, Delphi and Oberon on one branch. On another branch there's C, C++ and Java.[42]

BASIC (1964) stands for "Beginner's All Purpose Symbolic Instruction Code." It was developed at Dartmouth College for all of their students to learn.[43] If a student didn't go on to a more powerful language, the student would still remember Basic.[43] A Basic interpreter was installed in the microcomputers manufactured in the late 1970s. As the microcomputer industry grew, so did the language.[43]

Basic pioneered the interactive session.[43] It offered operating system commands within its environment:

However, the Basic syntax was too simple for large programs.[43] Recent dialects have added structure and object-oriented extensions. Microsoft's Visual Basic is still widely used and produces a graphical user interface.[44]

C programming language (1973) got its name because the language BCPL was replaced with B, and AT&T Bell Labs called the next version "C." Its purpose was to write the UNIX operating system.[34] C is a relatively small language -- making it easy to write compilers. Its growth mirrored the hardware growth in the 1980s.[34] Its growth also was because it has the facilities of assembly language, but uses a high-level syntax. It added advanced features like:

C allows the programmer to control which region of memory data is to be stored. Global variables and static variables require the fewest clock cycles to store. The stack is automatically used for the standard variable declarations. Heap memory is returned to a pointer variable from the malloc() function.

In the 1970s, software engineers needed language support to break large projects down into modules.[52] One obvious feature was to decompose large projects physically into separate files. A less obvious feature was to decompose large projects logically into abstract datatypes.[52] At the time, languages supported concrete (scalar) datatypes like integer numbers, floating-point numbers, and strings of characters. Concrete datatypes have their representation as part of their name.[53] Abstract datatypes are structures of concrete datatypes — with a new name assigned. For example, a list of integers could be called integer_list.

In object-oriented jargon, abstract datatypes are called classes. However, a class is only a definition; no memory is allocated. When memory is allocated to a class, it's called an object.[54]

Object-oriented imperative languages developed by combining the need for classes and the need for safe functional programming.[55] A function, in an object-oriented language, is assigned to a class. An assigned function is then referred to as a method, member function, or operation. Object-oriented programming is executing operations on objects.[56]

Object-oriented languages support a syntax to model subset/superset relationships. In set theory, an element of a subset inherits all the attributes contained in the superset. For example, a student is a person. Therefore, the set of students is a subset of the set of persons. As a result, students inherit all the attributes common to all persons. Additionally, students have unique attributes that other persons don't have. Object-oriented languages model subset/superset relationships using inheritance.[57] Object-oriented programming became the dominant language paradigm by the late 1990s.[52]

C++ (1985) was originally called "C with Classes."[58] It was designed to expand C's capabilities by adding the object-oriented facilities of the language Simula.[59]

An object-oriented module is composed of two files. The definitions file is called the header file. Here is a C++ header file for the GRADE class in a simple school application:

A constructor operation is a function with the same name as the class name.[60] It is executed when the calling operation executes the new statement.

A module's other file is the source file. Here is a C++ source file for the GRADE class in a simple school application:

Here is a C++ header file for the PERSON class in a simple school application:

Here is a C++ source code for the PERSON class in a simple school application:

Here is a C++ header file for the STUDENT class in a simple school application:

Here is a C++ source code for the STUDENT class in a simple school application:

Imperative languages have one major criticism: assigning an expression to a non-local variable may produce an unintended side effect.[61] Declarative languages generally omit the assignment statement and the control flow. They describe what computation should be performed and not how to compute it. Two broad categories of declarative languages are functional languages and logical languages.

The principle behind a functional language is to use lambda calculus as a guide for a well defined semantic.[62] In mathematics, a function is a rule that maps elements from an expression to a range of values. Consider the function:

The expression 10 * x is mapped by the function times_10() to a range of values. One value happens to be 20. This occurs when x is 2. So, the application of the function is mathematically written as:

A functional language compiler will not store this value in a variable. Instead, it will push the value onto the computer's stack before setting the program counter back to the calling function. The calling function will then pop the value from the stack.[63]

Imperative languages do support functions. Therefore, functional programming can be achieved in an imperative language, if the programmer uses discipline. However, functional languages force this discipline onto the programmer by removing the syntax of the assignment statement. Moreover, functional languages have a simpler syntax because they omit the overhead of the how in imperative languages.[64]

A functional program is developed with a set of primitive functions followed by a single driver function.[61] Consider the snippet:

The primitives are max() and min(). The driver function is difference_between_largest_and_smallest(). Executing:

Functional languages are used in computer science research to explore new language features.[65] Moreover, their lack of side-effects have made them popular in parallel programming and concurrent programming.[66] However, application developers prefer the object-oriented features of imperative languages.[66]

Lisp (1958) stands for "LISt Processor."[67] It is tailored to process lists. A full structure of the data is formed by building lists of lists. In memory, a tree data structure is built. Internally, the tree structure lends nicely for recursive functions.[68] The syntax to build a tree is to enclose the space-separated elements within parenthesis. The following is a list of three elements. The first two elements are themselves lists of two elements:

Lisp has functions to extract and reconstruct elements.[69] The function head() returns a list containing the first element in the list. The function tail() returns a list containing everything but the first element. The function cons() returns a list that is the concatenation of other lists. Therefore, the following expression will return the list x:

One drawback of Lisp is when many functions are nested, the parentheses may look confusing.[64] Modern Lisp environments help ensure parenthesis match. As an aside, Lisp does support the imperative language operations of the assignment statement and goto loops.[70] Also, Lisp is not concerned with the datatype of the elements at compile time. Instead, it assigns the datatypes at runtime. This may lead to programming errors not being detected early in the development process.

Writing large, reliable, and readable Lisp programs require forethought. If properly planned, the program may be much shorter than an equivalent imperative language program.[64] Lisp is widely used in artificial intelligence. However, its usage has been accepted only because it has imperative language operations, making unintended side-effects possible.[66]

ML (1973)[71] stands for "Meta Language." ML checks to make sure only data of the same type are compared with one another.[72] For example, this function has one input parameter (an integer) and returns an integer:

ML is not parenthesis-eccentric like Lisp. The following is an application of times_10():

It returns "20 : int". (Both the results and the datatype are returned.)

Like Lisp, ML is tailored to process lists. Unlike Lisp, each element is the same datatype.[73]

Prolog (1972) stands for "PROgramming in LOgic." It was designed to process natural languages.[74] The building blocks of a Prolog program are objects and their relationships to other objects. Objects are built by stating true facts about them.[75]

Set theory facts are formed by assigning objects to sets. The syntax is setName(object).

Relationships are formed using multiple items inside the parentheses. In our example we have verb(object,object). and verb(adjective,adjective).

After all the facts and relationships are entered, then a question can be asked:

Prolog's usage has expanded to become a goal-oriented language.[76] In a goal-oriented application, 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.[75] Practical applications include solving the shortest path problem[74] and producing family trees.[77]

Modular programming is a technique to refine imperative language programs. A program module is a sequence of statements that are bounded within a block and together identified by a name.[78] Modules have a function, context, and logic:[79]

The module's name should be derived first by its function, then by its context. Its logic should not be part of the name.[79] For example, function compute_square_root( x ) or function compute_square_root_integer( i : integer ) are appropriate module names. However, function compute_square_root_by_division( x ) is not.

The degree of interaction within a module is its level of cohesion.[79] Cohesion is a judgement of the relationship between a module's name and its function. The degree of interaction between modules is the level of coupling.[80] Coupling is a judgement of the relationship between a module's context and the elements being performed upon.

Data flow analysis is a design method used to achieve modules of functional cohesion and data coupling.[82] The input to the method is a data-flow diagram. A data-flow diagram is a set of ovals representing modules. Each module's name is displayed inside its oval. Modules may be at the executable level or the function level.

The diagram also has arrows connecting modules to each other. Arrows pointing into modules represent a set of inputs. Each module should have only one arrow pointing out from it to represent its single output object. (Optionally, an additional exception arrow points out.) A daisy chain of ovals will convey an entire algorithm. The input modules should start the diagram. The input modules should connect to the transform modules. The transform modules should connect to the output modules.[83]

Object-oriented programming need not be confined to an object-oriented language.[84] Object-oriented programming is executing operations on objects.[56] In object-oriented languages, classes are objects. In non-object-oriented languages, data structures (which are also known as records) may also be objects. To turn a data structure into an object, operations need to be written specifically for the structure. The resulting structure is called an abstract datatype.[85] However, inheritance will be missing. Nonetheless, this shortcoming can be overcome.

Here is a C programming language header file for the GRADE abstract datatype in a simple school application:

The grade_new() function performs the same algorithm as the C++ constructor operation.

Here is a C programming language source file for the GRADE abstract datatype in a simple school application:

In the constructor, the function calloc() is used instead of malloc() because each memory cell will be set to zero.

Here is a C programming language header file for the PERSON abstract datatype in a simple school application:

Here is a C programming language source code for the PERSON abstract datatype in a simple school application:

Here is a C programming language header file for the STUDENT abstract datatype in a simple school application:

Here is a C programming language source code for the STUDENT abstract datatype in a simple school application:

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.[87] The purpose of the operating system is to provide an environment where application software executes in a convenient and efficient manner.[87] 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 end users includes middleware, which couples one application with another. Both system software and application software execute utility programs.

Application software is the key to unlocking the potential of the computer system.[88] Enterprise application software bundles 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.[88] 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.[88]

The advantages of proprietary software are features and reports may be exact to specification.[89] 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.[89] The disadvantages of proprietary software are the time and resource costs may be extensive.[89] 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.[89] The disadvantages of off-the-shelf software are it may have unnecessary features that confuse end users, it may lack features the enterprise needs, and the data flow may not match the enterprise's work processes.[89]

One approach to economically obtaining a customized enterprise application is through an application service provider.[90] 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.[90] Many application service providers target small, fast-growing companies with limited information system resources.[90] On the other hand, larger companies with major systems will likely have their technical infrastructure in place. One risk is having to trust an external organization with sensitive information. Another risk is having to trust the provider's infrastructure reliability.[90]

An operating system is the low-level software that supports a computer's basic functions, such as scheduling tasks and controlling peripherals.[87]

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.[23] 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.[91]

The term operating system may refer to two levels of software.[92] The operating system may refer to the kernel program that manages the processes, memory, and devices. More broadly, the operating system may refer to the entire package of the central software. The package includes a kernel program, command-line interpreter, graphical user interface, utility programs, and editor.[92]

Originally, operating systems were programmed in assembly; however, modern operating systems are typically written in higher level languages like C, C++, Objective-C, and Swift.

A utility program is 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.[102] 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.[103]

Utility programs include compression programs so data files are stored on less disk space.[102] Compressed programs also save time when data files are transmitted over the network.[102] Utility programs can sort and merge data sets.[103] Utility programs detect computer viruses.

A stored-program computer requires an initial boot program stored in its read-only memory to boot. It is to identify and initialize all aspects of the system, from processor registers to device controllers to memory contents.[104] Following the initialization process, the boot 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 it must not be lost when the power is off.[91]

On a larger scale, an embedded microcontroller is used to control part of a larger system.[55] Examples include aircraft components and life support systems. Applications running on these systems are large and complex. Moreover, they run in real-time and must be robust.[55] The United States Department of Defense contracted with CII Honeywell Bull to develop Ada (1983) as a real-time programming language.[105]

Central to real-time systems is a task facility to permit parallel processing. Also important are interrupt controls.[105]

A microcode program is the bottom-level interpreter that controls the data path of software driven computers.[106] (Advances in hardware have migrated these operations to hardware execution circuits.)[106] Microcode instructions allow the programmer to more easily implement the digital logic level[107]—the computer's real hardware. The digital logic level is the boundary between computer science and computer engineering.[108]

A gate is a tiny transistor that can return one of two signals: on or off.[109]

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.[110] 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 random access memory.[111] The next step is to decode the machine instruction by selecting the proper output line to the hardware module.[112] 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).[113] 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.[114]

Microcode instructions move data between the CPU and the many computer buses. The disk controller bus writes to and reads from hard disk drives. Data is also moved between the CPU and other functional units via the peripheral component interconnect express bus.[115]