A declarative language, what are we talking about?
I can already hear you saying the what?
Well, to put it into simple terms, a declarative language is a language where we say, what will happen?
OK, I can see the gears spinning.
Right.
What will happen when we look at our school query?
We said select star from users.
We know we want to get data back.
We're saying what will happen?
Select star from users.
You're going to get feedback from users, but we have no idea how that's going to happen.
That's why we call it declarative.
We are simply stating something that is going to have on the counter end of that, we have what we call
imperative programming and imperative programming says how it will happen.
So what do we mean by that?
We just define that declarative, declarative meaning.
We see what will happen, but we have no idea how it's happening.
And on the other end, the imperative is saying how it will happen.
Imperative programming is where you go line by line by line, saying do this, do that, do that, go
read from over there in declarative.
You just say, give me this.
Let's break that down a bit more.
If we were to look at this, the man asking for a ham sandwich and getting one without having to do
anything, well, that's equivalent to declarative programming, right?
You say I want something.
This is what I want back.
This is what should happen.
And you get it back and however it happens is irrelevant to you.
It happens in a black box.
It happens somewhere behind the scenes.
And you don't know anything about what goes on there in an imperative programming.
You are the bandleader.
You are the one saying, let's do this, then let's do that, and then we will have an outcome.
So in the case of a ham sandwich, you are the one saying sliced the bread, slice the ham and putting
together the sandwich.
And if we were to look at some examples of declarative versus imperative programming, what we would
look at is, for instance, school.
Right.
We've already defined that.
That's on the declarative and select star from users.
Very clear, very straightforward.
You know that you're going to get user data back.
And Java, an old programming language that is still relevant today that some of you may have heard
of is a programming language where traditionally you would define everything that needs to happen.
You would define where you need to read from a hard drive where all of the data is.
And you would do all of the actions to get the data on the opposite end.
Something like Python can be both declarative and imperative.
You can do both with it.
We've created this clear divide and we've seen what declarative can do versus what imperative can do,
and it's more simple than it looks, right?
Declarative is very powerful because of its simplicity, because you don't have to worry about what's
going to happen behind the scenes.
And you can just say, hey, get me this, hey, get me that.
You can be more productive versus imperative.
You have more flexibility.
You have more power.
You can do way more things.
But it becomes more complicated as you go along because you have to manage all of these extra things.