Declarative Programming
Declarative programming describes what the result should be rather than specifying the step-by-step procedure to compute it. SQL, HTML, CSS, configuration languages, and logic programming are declarative: you state constraints or desired outcomes and let the runtime determine execution.
itSoftware engineering | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — Declarative Programming
Declarative programming means stating a result, relationship, or desired state and allowing an engine to work out much of the route. The work still happens. It has merely acquired an optimizer, controller, or compiler, which is help of a rather opinionated kind.
Keep the control boundary in view. Imperative code describes operations and their order. Declarative code describes what must hold while the engine decides much of the ordering, search, or evaluation. A SQL query requests rows; it does not bring a tiny database crew and dictate the access path.
A declaration can be an expression, query, rule, constraint, dependency graph, or desired-state object. A CSS rule waits for matching elements. A Make rule waits for prerequisites. A Kubernetes object waits for a controller to compare desired and observed state. The variety is real, but every form leaves some decisions to an engine.
The surprise is that compact declarations can still be expensive, risky, or wrong. A database can select an unexpected plan. A configuration change can replace a resource. A rule can lose through precedence. The declaration has not failed; it has delegated decisions that still need inspection.
Use three views. Read the declaration for intent. Inspect the execution plan for engine interpretation. Check observed output or state for reality. Testing a result or invariant is safer than demanding one hidden sequence of steps, which is a fine way to debate an optimizer that was never given voting rights.
Read the intro for the full map. Use the slides when the control boundary needs a picture. Keep the cheatsheet nearby when reviewing intent, plan, and reality. The practice reference turns the idea into a PostgreSQL query and an EXPLAIN plan, where engine choices become visible.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://www.haskell.org/onlinereport/haskell2010/
Supports
- Haskell expressions, function definitions, pattern bindings, types, and modules
- Expression-led functional programming as a declarative form
- https://www.postgresql.org/docs/current/tutorial-select.html
Supports
- SQL SELECT lists, table lists, Boolean qualifications, sorting, and duplicate removal
- Queries that specify result properties without fixing a physical access path
- https://www.postgresql.org/docs/current/using-explain.html
Supports
- Query plans, plan nodes, cost estimates, scan strategies, and runtime inspection
- Execution cost depending on engine plans and data access rather than query length
- https://www.w3.org/TR/css-cascade-5/
Supports
- CSS declarations, origins, importance, cascade layers, specificity, scope, and order
- Rule resolution that assigns property values to elements
- https://www.gnu.org/software/make/manual/make.html#Rule-Introduction
Supports
- Make rules composed of targets, prerequisites, and recipes
- Engine decisions about which targets require rebuilding
- https://developer.hashicorp.com/terraform/language
Supports
- Terraform as a declarative language for resources, expressions, and dependencies
- Operation ordering from implicit and explicit relationships rather than file order
- https://developer.hashicorp.com/terraform/intro
Supports
- Desired infrastructure state, resource graphs, state tracking, and change selection
- Version-controlled and reusable infrastructure configuration
- https://developer.hashicorp.com/terraform/cli/commands/plan
Supports
- Previewing proposed infrastructure changes before applying them
- Comparing configuration with prior and remote object state
- https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/
Supports
- Declarative creation and update of Kubernetes objects from configuration files
- Diff, apply, live configuration, merge behavior, and management tradeoffs
- https://kubernetes.io/docs/concepts/architecture/controller/
Supports
- Control loops that compare desired and current cluster state
- Repeated action that moves observed state toward desired state
- https://www.cs.utexas.edu/~moore/best-ideas/pltp/index.html
Supports
- Prolog development in 1972
- https://research.ibm.com/publications/sequel-a-structured-english-query-language
Supports
- SEQUEL publication in 1974
- https://www.gnu.org/software/make/manual/html_node/Introduction.html
Supports
- Make history
- https://www.w3.org/TR/REC-CSS1/
Supports
- CSS Level 1 in 1996
- https://www.haskell.org/onlinereport/preface-jfp.html
Supports
- Haskell 98 reports in 1999
- https://www.hashicorp.com/blog/announcing-terraform-0-1
Supports
- Terraform 0.1 in 2014
- https://kubernetes.io/blog/2015/07/kubernetes-v1-released/
Supports
- Kubernetes 1.0 in 2015
- https://blog.crossplane.io/crossplane-v1-0/
Supports
- Crossplane 1.0 in 2020
