Computer ScienceProgrammingMedium

Functional Programming

Also known as:FPdeclarative programming (partial overlap)pure functional programming

Functional programming (FP) is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state or mutable data. Core principles include pure functions (same input always yields same output, no side effects), immutability, first-class and higher-order functions, and function composition. FP promotes code that is predictable, testable, and parallelisable, and is embodied in languages such as Haskell, Erlang, Clojure, and adopted extensively in Scala, F#, and modern JavaScript/Python.

Functional vs Imperative Programming Compared

AspectFunctionalImperativeExample
StateImmutableMutableval vs var
Control flowRecursion, map/filterLoops (for, while)map() vs for loop
Side effectsAvoided / isolatedCommonIO monads vs direct I/O
FunctionsFirst-class, higher-orderMay be second-classPassing functions as args
DebuggingEasier (pure functions)Harder (shared state)Unit testing pure fns
PerformanceCan be lower (GC)Can be higher (in-place)Haskell vs C

Interactive Tools

Codecademy – Functional Programming in Python

Open Tool

Brilliant – Functional Programming

Open Tool

Khan Academy – Computer Science

Open Tool
Diagram of a mathematical function machine showing input, function, and output

Wikimedia Commons, CC BY-SA

Related Terms

The paradigm is rooted in Alonzo Church's lambda calculus (1930s). "Functional programming" as a term was popularised by John Backus in his 1977 Turing Award lecture "Can Programming Be Liberated from the von Neumann Style?", advocating FP over imperative style.

functional-programmingimmutabilitypure-functionshaskelllambdaparadigm