DEV Community

DeChamp
DeChamp

Posted on

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

Top comments (0)