Functional Programming
Also known as: FP
Programming paradigm that builds software by composing pure functions, treating computation as evaluating expressions rather than changing state.
Functional programming is a style in which programs are constructed mainly from functions that take inputs and return outputs, with as little mutable state and as few side effects as possible. Instead of a loop that repeatedly updates a running total, a functional program might apply a summing function to a list. Core ideas include pure functions, immutable data, first-class and higher-order functions, recursion in place of loops and the composition of small functions into larger ones. Some languages are purely functional; many others support the style alongside other paradigms.
The paradigm's roots lie in Alonzo Church's lambda calculus of the 1930s. Lisp, designed by John McCarthy in 1958, brought functional ideas into practical programming, followed by ML in the 1970s and Haskell, a purely functional language designed by a committee and first defined in 1990. John Backus, who led the creation of FORTRAN, used his 1977 Turing Award lecture to argue for a functional alternative to conventional programming. Erlang, developed at Ericsson for telephone switching systems, showed that functional languages could run large, fault-tolerant production systems.
Functional ideas have spread well beyond specialist languages. JavaScript programmers routinely use map and filter, and React encourages components written as functions of their inputs. Java and C# added lambdas and streams, while Rust borrows heavily from ML. Avoiding shared mutable state makes code easier to test and safer to run in parallel, and the approach influenced large-scale data processing models such as MapReduce. Critics point to a steeper learning curve, unfamiliar abstractions such as monads and performance costs in some settings, so most practical code blends functional and imperative styles.
Key points
- Functional programming favors pure functions, immutable data and composition over mutable state and step-by-step updates.
- The paradigm descends from Alonzo Church's lambda calculus and entered practice through Lisp in 1958.
- Haskell, ML, Erlang and Clojure are prominent functional languages, and many mainstream languages support the style.
- Limiting side effects makes code easier to test, reason about and run in parallel.
Related entries
Pure Function
Function that always returns the same output for the same inputs and has no side effects, such as modifying outside state or performing I/O.
Higher-Order Function
Function that takes other functions as arguments or returns a function as its result, such as map, filter and reduce.
Closure
Function bundled with references to variables from the scope where it was created, letting it keep using them after that scope has finished.
Mutability
The property that determines whether an object or value can be changed after it is created; immutable values stay fixed once made.
Recursion
Technique in which a function solves a problem by calling itself on smaller instances of the same problem until it reaches a simple base case.
Lisp
Family of programming languages originated by John McCarthy in 1958, built on symbolic expressions and long associated with AI research.
Object-Oriented Programming
Programming paradigm that organizes software around objects, which bundle data with the methods that operate on it and interact by sending messages.
John McCarthy
American computer scientist who coined the term artificial intelligence, created the Lisp programming language and pioneered time-sharing.
Featured in guides
Referenced by
Other entries that discuss or point to Functional Programming.