All Topics  
Imperative programming

 

   Email Print
   Bookmark   Link






 

Imperative programming



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, imperative programming is a programming paradigm
Programming paradigm

A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
 that describes computation in terms of statement
Statement (programming)

In computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements....
s that change a program state
State (computer science)

In computer science and automata theory, a state is a unique configuration of information in a program or machine. It is a concept that occasionally extends into some forms of systems programming such as Lexical analysiss and parsers....
. In much the same way as the imperative mood
Imperative mood

The imperative mood is a grammatical mood that expresses direct commands or requests. It is also used to signal a prohibition, permission or any other kind of exhortation....
 in natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
s expresses commands to take action, imperative programs define sequences of commands for the computer to perform.

The term is used in opposition to declarative programming
Declarative programming

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow....
, which expresses what needs to be done, without prescribing how to do it in terms of sequences of actions to be taken.






Discussion
Ask a question about 'Imperative programming'
Start a new discussion about 'Imperative programming'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, imperative programming is a programming paradigm
Programming paradigm

A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
 that describes computation in terms of statement
Statement (programming)

In computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements....
s that change a program state
State (computer science)

In computer science and automata theory, a state is a unique configuration of information in a program or machine. It is a concept that occasionally extends into some forms of systems programming such as Lexical analysiss and parsers....
. In much the same way as the imperative mood
Imperative mood

The imperative mood is a grammatical mood that expresses direct commands or requests. It is also used to signal a prohibition, permission or any other kind of exhortation....
 in natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
s expresses commands to take action, imperative programs define sequences of commands for the computer to perform.

The term is used in opposition to declarative programming
Declarative programming

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow....
, which expresses what needs to be done, without prescribing how to do it in terms of sequences of actions to be taken. Functional
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 and logical programming are examples of a more declarative approach.

Imperative, procedural, and declarative programming


Procedural programming
Procedural programming

Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call....
 is imperative programming in which the statements are structured into procedures (also known as subroutines or functions); the terms are often used as synonyms, but the use of procedures has a dramatic impact on what imperative programs look like and how they are constructed. Heavily procedural programming, in which state changes are localized to procedures or restricted to explicit arguments and returns from procedures, is known as structured programming
Structured programming

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement ....
; from the 1960s onwards, it has been propagated as a technique to improve the maintainability
Maintainability

In software engineering, the ease with which a software product can be modified in order to:* correct defects* meet new requirements* make future maintenance easier, or...
 and overall quality of imperative programs. Object-oriented programming
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
 extends this approach.

Procedural programming is a step towards declarative programming: by just looking at the names, arguments and return types of procedures, and comments added by the programmer, we can often understand what a procedure is supposed to do without understanding how. At the same time, a complete program is imperative: it fixes the statements to be executed and their order of execution to a large extent.

Declarative programming
Declarative programming

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow....
 is a non-imperative style of programming in which programs describe the desired results of the program, without explicitly listing command or steps that need to be carried out to achieve the results. Functional
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 and logical programming languages are characterized by a declarative programming style.

In a pure functional language, such as Haskell
Haskell (programming language)

Haskell is a standardized, purely functional programming language with non-strict programming language, named after logician Haskell Curry. The goals of the language are described as:...
, all functions are without side effects
Pure function

In computer programming, a function may be described as pure if both these statements about the function hold:# The function always evaluates the same result value given the same argument value....
, and state changes are only represented as functions that transform the state. Although pure functional languages are non-imperative, they often provide a facility for describing the effect of a function as a series of steps. Other functional languages, such as Lisp, OCaml and Erlang, support a mixture of procedural and functional programming.

In logical programming languages
Logic programming

Logic programming is, in its broadest sense, the use of mathematical logic for computer programming. In this view of logic programming, which can be traced at least as far back as John McCarthy 's [1958] Advice taker proposal, logic is used as a purely Declarative programming language representation language, and a automated theorem proving o...
, programs consist of logical statements, and the program executes by searching for proofs of the statements. As for functional programming languages, some logical programming languages such as Prolog
Prolog

Prolog is a logic programming language. It is a general purpose language often associated with artificial intelligence and computational linguistics....
, and database query languages such as SQL
SQL

SQL is a database computer language designed for the retrieval and management of data in relational database management systems , database schema creation and modification, and database object access control management....
, while declarative in principle, also support a procedural style of programming.

Overview

The hardware implementation of almost all computers is imperative; nearly all computer hardware is designed to execute machine code
Machine code

Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit. Machine code may be regarded as a primitive programming language or as the lowest-level representation of a compiled and/or assembly language computer program....
, which is native to the computer, written in the imperative style. From this low-level perspective, the program state is defined by the contents of memory, and the statements are instructions in the native machine language of the computer. Higher-level imperative languages use variable
Variable

A variable is a symbol that stands for a value that may vary; the term usually occurs in opposition to constant, which is a symbol for a non-varying value, i.e....
s and more complex statements, but still follow the same paradigm. Recipe
Recipe

A recipe is a set of instructions that show how to prepare or make something, especially a culinary dish .Modern culinary recipes normally consist of several components:...
s and process checklist
Checklist

A checklist is used as an aid to memory. It helps to ensure consistency and completeness in carrying out a task. A basic example is the "to do list." A more advanced checklist would be a schedule, which lays out tasks to be done according to time of day or other factors....
s, while not computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
s, are also familiar concepts that are similar in style to imperative programming; each step is an instruction, and the physical world holds the state. Since the basic ideas of imperative programming are both conceptually familiar and directly embodied in the hardware, most computer languages are in the imperative style.

Assignment statements
Assignment (computer science)

In computer science the assignment statement sets or re-sets the Value stored in the storage location denoted by a variable name. In most imperative programming computer programming languages the assignment statement is one of the basic Statement s....
, in general, perform an operation on information located in memory and store the results in memory for later use. High-level imperative languages, in addition, permit the evaluation
Evaluation (disambiguation)

Evaluation is the process of characterizing and appraising something of interest or of determining the value of an expression ....
 of complex expressions
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
, which may consist of a combination of arithmetic operations
Arithmetic

Arithmetic or arithmetics is the oldest and most elementary branch of mathematics, used by almost everyone, for tasks ranging from simple day-to-day counting to advanced science and business calculations....
 and function
Function (mathematics)

The mathematical concept of a function expresses dependence between two quantities, one of which is known and the other which is produced. A function associates a single output to each input element drawn from a fixed Set , such as the real numbers , although different inputs may have the same output....
 evaluations, and the assignment of the resulting value to memory. Looping statements (such as in while loop
While loop

In most computer programming languages, a while loop is a Control flow statement that allows code to be executed repeatedly based on a given Boolean datatype condition....
s, do while loop
Do while loop

In most computer programming languages, a do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean datatype condition....
s and for loop
For loop

In computer science a for loop is a programming language statement which allows code to be repeatedly execution . A for loop is classified as an iteration statement....
s) allow a sequence of statements to be executed multiple times. Loops can either execute the statements they contain a predefined number of times, or they can execute them repeatedly until some condition changes. Conditional branching
Branch (computer science)

A branch is a point in a computer program where the flow of control is altered. The term branch is usually used when referring to a program written in machine code or assembly language; in a high-level programming language, branches usually take the form of conditional statements, subroutine calls or GOTO statements....
 statements allow a block of statements
Statement block

In computer programming, a statement block is a section of computer code which is grouped together, much like a paragraph; such blocks consist of one, or more, statement ....
 to be executed only if some condition is met. Otherwise, the statements are skipped and the execution sequence continues from the statement following the block. Unconditional branching statements allow the execution sequence to be transferred to some other part of the program. These include the jump, called "goto
GOTO

GOTO is a statement found in many computer programming languages. It is a combination of the English words wiktionary:go and wiktionary:to....
" in many languages, and the subprogram, or procedure
Procedure

A procedure is a specified series of actions, acts or operations which have to be executed in the same manner in order to always obtain the same result under the same circumstances ....
, call.

History

The earliest imperative languages were the machine languages of the original computers. In these languages, instructions were very simple, which made hardware implementation easier, but hindered the creation of complex programs. FORTRAN
Fortran

Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
, developed by John Backus
John Backus

For the physicist, see John Backus John Warner Backus was an American computer scientist. He led the team that invented the first widely used High-level programming language programming language and was the inventor of the Backus-Naur form , the almost universally used notation to define formal language syntax....
 at IBM starting in 1954, was the first major programming language to remove the obstacles presented by machine code in the creation of complex programs. FORTRAN was a compiled language
Compiled language

A compiled language is a programming language whose programming language implementations are typically compilers , and not interpreter s .The term is somewhat vague; in principle any language can be implemented with a compiler or with an interpreter....
 that allowed named variables, complex expressions, subprograms, and many other features now common in imperative languages. The next two decades saw the development of a number of other major high-level imperative programming languages. In the late 1950s and 1960s, ALGOL
Algol

Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered....
 was developed in order to allow mathematical algorithms to be more easily expressed, and even served as the operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
's target language for some computers. COBOL
COBOL

COBOL is one of the oldest programming languages still in active use. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....
 (1960) and BASIC
BASIC

In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students....
 (1964) were both attempts to make programming syntax look more like English. In the 1970s, Pascal was developed by Niklaus Wirth
Niklaus Wirth

Niklaus Emil Wirth is a Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
, and C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 was created by Dennis Ritchie
Dennis Ritchie

Dennis MacAlistair Ritchie is an American computer science notable for his influence on C and other programming languages, and on operating systems such as Multics and Unix....
 while he was working at Bell Laboratories. Wirth went on to design Modula-2
Modula-2

Modula-2 is a computer programming language invented by Niklaus Wirth at ETH, around 1978, as a successor to his intermediate language Modula. Modula-2 was implemented in 1980 for the Lilith computer, which was commercialized in 1982 by startup company DISER as MC1 and MC2....
, and Oberon. For the needs of the United States Department of Defense
United States Department of Defense

The United States Department of Defense is the federal department charged with coordinating and supervising all agencies and functions of the government relating directly to national security and the Military of the United States....
, Jean Ichbiah
Jean Ichbiah

Jean David Ichbiah was a France-born computer scientist and the chief designer of Ada programming language, a general-purpose, strongly-typed programming language with certified validated compilers....
 and a team at Honeywell
Honeywell

Honeywell is a major United States multinational corporation list of conglomerates company that produces a variety of consumer products, engineering services, and aerospace systems for a wide variety of customers, from private consumers to major corporations and governments....
 began designing Ada in 1978, after a 4-year project to define the requirements for the language. The specification was first published in 1983, with revisions in 1995 and 2005/6.

The 1980s saw a rapid growth in interest in object-oriented programming
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
. These languages were imperative in style, but added features to support objects. The last two decades of the 20th century saw the development of a considerable number of such programming languages. Smalltalk-80, originally conceived by Alan Kay
Alan Kay

Alan Curtis Kay is an United States computer scientist, known for his early pioneering work on object-oriented programming and Window graphical user interface design....
 in 1969, was released in 1980 by the Xerox Palo Alto Research Center. Drawing from concepts in another object-oriented language—Simula
Simula

Simula is a name for two programming languages, Simula I and Simula 67, developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard....
 (which is considered to be the world's first object-oriented programming language
Object-oriented programming language

An object-oriented programming language is one that allows or encourages, to some degree, object-oriented programming techniques such as Information hiding, Inheritance , module , and Polymorphism ....
, developed in the late 1960s)—Bjarne Stroustrup
Bjarne Stroustrup

Bjarne Stroustrup is a computer scientist at the College of Engineering Chair Professor of Computer Science at Texas A&M University. He is most notable for developing the C++ programming language....
 designed C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
, an object-oriented language based on C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
. C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
 was first implemented in 1985. In the late 1980s and 1990s, the notable imperative languages drawing on object-oriented concepts were Perl
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
, released by Larry Wall
Larry Wall

Larry Wall is a programmer and author, most widely known for his creation of the Perl programming language in 1987....
 in 1987; Python
Python (programming language)

Python is a general-purpose high-level programming language. Its design philosophy emphasizes code readability. Python's core syntax and semantics are Minimalism , while the standard library is large and comprehensive....
, released by Guido van Rossum
Guido van Rossum

Guido van Rossum is a Netherlands computer programmer who is best known as the author of the Python . In the Python community, Van Rossum is known as a ?Benevolent Dictator for Life? , meaning that he continues to oversee the Python development process, making decisions where necessary....
 in 1990; PHP
PHP

PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in Standalone software Graphical user interface....
, released by Rasmus Lerdorf
Rasmus Lerdorf

Rasmus Lerdorf is a Denmark-Greenlandic programmer and is most notable as the creator of the PHP programming language. He authored the first two versions....
 in 1994; Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, first released by Sun Microsystems
Sun Microsystems

Sun Microsystems, Inc. is a multinational corporation vendor of computers, computer components, computer software, and information technology services, founded on February 24, 1982....
 in 1994 and Ruby
Ruby (programming language)

Ruby is a dynamic programming language, reflection , general purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features....
, released in 1995 by Yukihiro “matz” Matsumoto.

Category:Procedural programming languages lists additional imperative programming languages.


See also

  • Declarative programming
    Declarative programming

    In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow....
     (contrast)
  • Programming paradigm
    Programming paradigm

    A programming paradigm is a fundamental style of computer programming. . Paradigms differ in the concepts and abstractions used to represent the elements of a program and the steps that compose a computation ....
    s
  • Object-oriented programming
    Object-oriented programming

    Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....


External links



Originally based on the article 'Imperative programming' by Stan Seibert, from Nupedia
Nupedia

Nupedia was an English-language World Wide Web encyclopedia whose articles were written by experts and licensed as free content. It was founded by Jimmy Wales and underwritten by Bomis, with Larry Sanger as editor-in-chief....
, licensed under the GNU Free Documentation License
GNU Free Documentation License

The GNU Free Documentation License is a copyleft license for free documentation, designed by the Free Software Foundation for the GNU Project....
.