programming paradigm

term

programming

Kept in this browser · My desk

A style of organizing programs that a language makes easy: commands that change memory (imperative), objects that answer messages, functions composed without mutation, facts and rules searched by the system, descriptions of a result, or communicating workers.

Structured programming followed Dijkstra's 1968 letter; Simula 67 (1967) and Smalltalk (1972 to 1980) created object orientation, a name Alan Kay says he coined; Lisp and ML grew functional programming; Prolog (1972) logic programming; Go's goroutines and channels descend from Hoare's Communicating Sequential Processes (CSP).

What it is. A programming paradigm is a style of organizing programs that a language makes easy: commands that change memory (imperative), objects that answer messages, functions composed without mutation, facts and rules that the system searches, descriptions of a result, or communicating workers. The word is borrowed from the history of science, and Alan Kay used it in that sense: the Smalltalk group, he wrote, was "trying for a qualitative shift in belief structures", "a new Kuhnian paradigm".

The same task shows the difference. Summing the squares of the even numbers in 3, 1, 4, 1, 5, 9, 2, 6 gives 56 in every paradigm: a C loop updating a total (imperative and structured); a Java object that owns the list and answers a message (object-oriented); an ML expression that filters, maps and folds without changing anything (functional); three Prolog clauses that state what the sum is and let the system search (logic); one SQL query, SELECT SUM(v * v) ... WHERE v % 2 = 0 (declarative); and Go workers sending squares over a channel to a single owner of the total (concurrent: "share memory by communicating").

Structured and object-oriented. Structured programming followed Edsger Dijkstra's 1968 letter against the go to statement: programs built from sequence, selection and loops whose shape matches their execution. Object orientation came from simulation. Kristen Nygaard and Ole-Johan Dahl gave Simula 67 classes, prefixing (inheritance) and, for the Lysebu conference of May 1967, "the more neutral word 'object'"; Alan Kay at Xerox's Palo Alto Research Center (PARC) built Smalltalk on objects that hide their state and process and communicate only by messages, and wrote that its contribution was "a new design paradigm, which I called object-oriented". Dan Ingalls stated the principle for Smalltalk-80 in BYTE in August 1981: "Computing should be viewed as an intrinsic capability of objects that can be uniformly invoked by sending messages."

What object-oriented meant at the source. Kay's history lists the "six main ideas" Smalltalk had settled on by the early 1970s: everything is an object; objects communicate by sending and receiving messages; objects have their own memory; every object is an instance of a class, which must itself be an object; the class holds the shared behaviour for its instances; and to evaluate a program list, control passes to the first object and the remainder is treated as its message. Much of what later languages call object-oriented (classes as templates, inheritance as the main tool) is closer to Simula's half of the story than to Kay's emphasis on messages.

Functional. Lisp and ML grew functional programming. John Backus's 1977 Turing Award lecture, Can Programming Be Liberated from the von Neumann Style?, called the descendants of FORTRAN "fat and weak", tied to word-at-a-time programming, and argued for functional styles; in it he proposed FP, a functional language with an algebra of programs.

Logic. Prolog, from Alain Colmerauer and Philippe Roussel in Marseille in 1972, made logic programming practical. Robert Kowalski, who worked on the theory in Edinburgh, warned in The Early Years of Logic Programming (Communications of the Association for Computing Machinery, ACM, January 1988) that the name is ambiguous: it was meant for the language, but came to stand for logic programming in general, and "claims made for the general concept of logic programming do not always hold for the programming language, Prolog, and vice versa".

Concurrent. Tony Hoare's Communicating Sequential Processes (Communications of the ACM, August 1978) argued that "input and output are basic primitives of programming and that parallel composition of communicating sequential processes is a fundamental program structuring method"; in his design the processes "may not communicate with each other by updating global variables". Go's goroutines and channels descend from it, and the Go frequently asked questions (FAQ) page quotes the proverb "Do not communicate by sharing memory. Instead, share memory by communicating."

Mixed in practice. Most modern languages (Python, JavaScript, Kotlin, Swift, Rust, C#) mix paradigms; a paradigm is a lens on a program rather than a box a language fits in. The choice still matters: each paradigm makes some mistakes impossible and others easy. Shared mutable state, which imperative code takes for granted, is the source of data races that the concurrent and functional styles avoid; deep inheritance hierarchies, an object-oriented habit, make changes ripple; and logic programs depend on a search order the reader cannot see.

What goes wrong. Paradigm debates turn into identity, and a team that writes one paradigm in a language built for another gets the worst of both. The useful question is narrower: which errors does this style rule out, and which does it invite?

Neighbours. Paradigms are properties of programming languages: imperative ones descend from FORTRAN and ALGOL, object-oriented ones from Simula and Smalltalk, functional ones from Lisp and ML, logic ones from Prolog, and concurrent ones from Hoare's CSP. Brazilian practice says paradigma de programação.

Also known as: paradigm, imperative programming, object-oriented programming, functional programming, logic programming, declarative programming, paradigma de programação

Sources

← Back to P Back to the glossary