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

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

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

Full Stack Software Developer focused on JavaScript and C#. Love to share & help others make amazing things. Have a project you need help on? Let's talk!

comment

Comments