LLMpediaThe first transparent, open encyclopedia generated by LLMs

Declarative programming

Generated by DeepSeek V3.2
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: Cascading Style Sheets Hop 4
Expansion Funnel Raw 73 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted73
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
Declarative programming
NameDeclarative programming
ParadigmMulti-paradigm
FamilyProgramming language
InfluencedFunctional programming, Logic programming, Constraint programming

Declarative programming. It is a style of building the structure and elements of computer programs that expresses the logic of a computation without describing its control flow. Instead of specifying a sequence of commands, it declares the properties of the desired result, often using mathematical logic or set-theoretic expressions. This paradigm contrasts with imperative programming and is the foundation for several major subparadigms, including functional and logic programming.

Overview

The core principle is to describe *what* a program should accomplish, rather than *how* to achieve it through step-by-step instructions. This approach often involves writing expressions that are evaluated by a supporting system, such as an interpreter or runtime engine. Key domains utilizing this style include database querying with SQL, user interface specification in React and Vue.js, and configuration management with tools like Puppet and Ansible. The paradigm's mathematical roots are evident in languages like Prolog and Haskell.

Characteristics

Programs are typically built from declarative statements that define relationships, constraints, and goals. State changes and explicit control flow, common in languages like C or Java, are minimized or abstracted away. Evaluation often relies on techniques like pattern matching, backtracking, and lazy evaluation, as seen in implementations for Erlang and the Glasgow Haskell Compiler. This leads to code that is frequently more concatenative, idempotent, and easier to reason about formally.

Comparison with imperative programming

While imperative programming, exemplified by ALGOL, Fortran, and Python, focuses on commands that change a program's state, the declarative approach abstracts state management. For instance, a SQL `SELECT` statement declares data conditions without specifying the algorithm for table traversal, unlike a loop in COBOL. This difference is central to the von Neumann architecture versus more abstract computational models. The Church–Turing thesis underpins the equivalence in capability between the paradigms, despite their contrasting styles.

Subparadigms and languages

Major subparadigms include **functional programming**, which uses mathematical functions and avoids mutable data, as in Haskell, Lisp, and Standard ML. **Logic programming**, centered on formal logic and theorem proving, is embodied by Prolog and Datalog. **Constraint programming**, used for satisfiability problems, appears in languages like Oz. Other notable examples are SQL for databases, XSLT for XML transformations, and HTML for web content structure.

Applications and examples

It is extensively applied in **database systems**, where SQL queries declaratively manipulate data in systems like Oracle and SQL Server. In **web development**, frameworks such as React use declarative components to model the DOM. **Configuration management** tools like Ansible and Terraform declare the desired state of infrastructure. **Domain-specific languages** (DSLs), including regular expressions and YAML, are also declarative, as are modeling languages like Alloy and UML.

History and development

Early influences include the **lambda calculus** developed by Alonzo Church and the concept of **recursive functions** from Kurt Gödel. The 1970s saw the advent of key languages: Prolog was created by Alain Colmerauer and Robert Kowalski, while John Backus advocated for functional programming in his Turing Award lecture on FP. The 1980s and 1990s brought standardization efforts like Common Lisp, Haskell 98, and SQL-92. Contemporary developments are driven by organizations like the W3C (e.g., SPARQL) and the rise of declarative cloud orchestration.

Category:Programming paradigms