DEV Community

DeChamp
DeChamp

Posted on

2 1

What is Declarative vs Imperative

So this is one that even to this day, I have to google every now and then. I'm making an effort to write a post from now on, any time I have to research something. The hope is it'll help me remember and also that it will help someone else in the same boat!

So here it goes.

I just watched a great video on it that does a great job to explain the difference. You can find it here.

Chris Boesch says in the video, that it's simplest form is as follows.

  • Imperative: How to do something
  • Declarative: What to do

The example Chris gives further is that of when you get in a Taxi.

Imperative would be if you gave the Taxi driver a step by step instruction of how to get where you are going.

Declarative is like saying "take me to the white house"

If you want a code example, definitely watch the video linked above.

One last way to remember, borrowed from zsoc on IRC ##javascript, he stated declarative... as in 'declaring' something.. like "I'm going to do this thing" vs "this is how im going to do something"

anywho, hope that helps some of ya.

--DeChamp

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay