Difference Between Declarative and Imperative Programming in 60 Seconds

The terms declarative and imperative are often thrown around when talking about different styles in programming. Here's a short way to tell the difference.


Declarative "declares" a statement.

  • Get Groceries
  • My name is Matt
  • <img src="abc.jpg">
  • [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
  • Sum(orders)


Imperative gives step by step instructions how to do something.

decimal total = 0m;
decimal salesTax = 0.23m;
foreach (var order in orders)
    total += order.Total;

total = total + (total * salesTax);

Declarative programming is often an abstraction layer on top of imperative code.

Matt Ferderer

Software engineer who spends his time learning about building teams, project management, software architecture, C#, .NET Core, Blazor, JavaScript, TypeScript, Azure, user experience, web security, and performance.