Imperative vs. Declarative Languages

Yan Cui

I help clients go faster for less using serverless technologies.

This article is brought to you by

Is your CI build step taking too long? Try Depot for free today and experience up to 40x faster build speed!

Unlock faster CI for FREE

Following my previous post on multi-language (polyglot) and multi-paradigm (poly-paradigm) development, I thought I’d continue on the same thread for a little and do some comparisons on some of the popular types of programming languages.


An imperative programming language such as C# or Java allows you to specify step-by-step how a problem should be solved using a series of statements which change a program’s state. It’s important to remember that whilst Object Oriented Programming is how we are all taught to do imperative programming these days, it’s not the only way – C and other procedural languages are also imperative languages.

A declarative programming language on the other hand, is a higher level programming language which allows you to express what you want without specifying how to get it. SQL is probably the most widely used declarative language today and in SQL you don’t tell the query analyzer how to go about fetching the data, you just state what data you want to retrieve and it takes care of the rest. It’s also worth nothing that

How they compare:

The benefit of declarative language is that it separates the process of stating a problem from the process of solving it. It’s essentially an extension of design by contract where producers of the declarative input describe what they need and how they need it, allowing producers of the declarative program to determine the best way to get it.

Approximating this in an imperative language is possible because at heart, everything is imperative. The challenge in doing so is that an imperative program operating on declarative input must be prepared to check pre and post conditions and have a plan to deal with every eventuality!

Declarative languages allows for greater extensibility, agility and productivity. Think how quickly you can create a table, input some data and then get the data back in some form or another in SQL and then imagine the time and effort it’d require if you were to implement these in C#.

However, as a user of a declarative language, you have limited or no control over how your inputs are dealt with and therefore have no option but to mitigate the impact of any imperfections/bugs in the underlying language and rely on the providers of the declarative language to address the issues.

Whenever you’re ready, here are 4 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
  2. Do you want to know how to test serverless architectures with a fast dev & test loop? Check out my latest course, Testing Serverless Architectures and learn the smart way to test serverless.
  3. I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
  4. Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.

2 thoughts on “Imperative vs. Declarative Languages”

  1. Pingback: Avishkar's Blog » Imperative vs. Declarative Languages

Leave a Comment

Your email address will not be published. Required fields are marked *