Declarative programming
Declarative programming is a programming paradigm where you describe what you want to compute rather than how to compute it. Instead of writing step-by-step instructions, you declare desired outcomes, constraints, or rules—and let the system figure out the computational path.
A declarative approach contrasts sharply with imperative programming, which focuses on explicit commands and control flow. In declarative code, you might specify "find all users over 18" without detailing loops or conditionals. The underlying software engine handles the machinery.
Common declarative approaches include:
- Query languages like SQL, which let you declare what data you want
- Markup systems like HTML and CSS, which describe structure and appearance
- Constraint solvers, which find solutions satisfying stated constraints
- Functional paradigms, emphasizing immutable data and pure functions
- Logic programming, based on mathematical rules and inference
Declarative programming shines when readability and maintainability matter more than low-level control. It's especially powerful for integrating complex systems—think configuration files, UI frameworks like Elements, or probabilistic reasoning.
The trade-off: less control over performance details, but often cleaner, more expressive code.
Related
Functional programming, SQL, Logic programming, HTML, Constraint satisfaction, Epistemology