What is declarative?

Declarative is a style of programming (or describing something) where you focus on what you want to happen, not how to make it happen. You write statements that describe the desired result, and the system figures out the steps to achieve it.

Let's break it down

Think of ordering a pizza. In a declarative approach you say, “I want a large pepperoni pizza.” You don’t tell the chef how to knead the dough, spread the sauce, or bake it. In code, you write something like SELECT * FROM users WHERE age > 30 - you describe the data you need, not the loop that scans each row.

Why does it matter?

Because it lets you write less code, makes programs easier to read, and reduces bugs. The underlying engine handles the complex details, so you can concentrate on the problem you’re solving instead of low‑level mechanics.

Where is it used?

  • Database queries (SQL, GraphQL)
  • UI frameworks (React’s JSX, SwiftUI, Jetpack Compose)
  • Build tools (Make, Terraform)
  • Configuration files (Kubernetes YAML, Docker Compose)
  • Functional programming languages (Haskell, Elm)

Good things about it

  • Simplicity: Clear, high‑level intent.
  • Maintainability: Easier to change requirements without rewriting loops.
  • Optimization: The system can choose the most efficient way to execute your request.
  • Parallelism: Declarative code often allows automatic parallel execution.

Not-so-good things

  • Less control: You can’t fine‑tune every step, which may be needed for performance‑critical tasks.
  • Steeper learning curve: Understanding how the system interprets your statements can be confusing at first.
  • Debugging difficulty: Errors may surface deep inside the engine, making them harder to trace.
  • Tooling dependence: You rely on the underlying engine’s quality and updates.