Declarative Programming
Subject: Computer and Technology noun /dɪˈklɛr.ə.tɪv ˈproʊ.ɡræm.ɪŋ/ 1 definition
- programming-paradigms
- programming-languages
- software-engineering
- computer-science
-
Definition (noun)
Entry #266 · UpdatedDeclarative Programming is a programming paradigm in which programs describe the desired computation result, logical relationships, or target system state rather than prescribing explicit step-by-step execution instructions. Instead of manually mutating variables, managing loop counters, or ordering low-level operations, authors specify constraints, queries, expressions, or state declarations and delegate execution planning, optimization, and reconciliation to an underlying runtime, compiler, or engine. This contrasts directly with imperative programming, where program behavior is defined through sequential commands that mutate shared state across explicit conditional branches and loops. By abstracting away control-flow mechanics, declarative programming improves conciseness, reasoning, and idempotency, though it trades fine-grained manual control over execution order and memory usage for reliance on the underlying engine's optimizer.
Common Forms
Functional Programming: Models computation as the composition of pure, stateless functions over immutable data rather than sequential state mutations, as implemented in languages like Haskell, Elm, and Clojure.
Logic Programming: Represents knowledge as formal facts and inference rules, allowing a resolution engine such as Prolog or Datalog to derive answers that satisfy a declared query without explicit search-loop code.
Query and Dataflow Languages: Declares desired data filters, joins, aggregations, or value dependencies—used in SQL, GraphQL, and reactive spreadsheets—so a query planner or dependency graph can determine optimal execution order.
Declarative Configuration and UI: Specifies target infrastructure, deployment topologies, styling rules, or component trees as structured state definitions in tools like Terraform HCL, Kubernetes manifests, CSS, and React JSX, leaving diffing and state reconciliation to a controller.
Example
To compute revenue per customer in PostgreSQL, a developer runs
SELECT customer_id, SUM(amount_cents) FROM orders WHERE status = 'paid' AND created_at >= '2026-01-01' GROUP BY customer_id;without writing loops or file-access logic. Instead of executing imperative steps dictated by the caller, PostgreSQL's query planner evaluates table statistics and automatically selects an execution plan—such as a B-tree index scan paired with hash aggregation—to produce the declared result set.