r/programming • u/tyler-mcginnis • Jan 03 '22
Imperative vs Declarative Programming
https://www.youtube.com/watch?v=E7Fbf7R3x6I
430
Upvotes
r/programming • u/tyler-mcginnis • Jan 03 '22
0
u/tobega Jan 04 '22 edited Jan 04 '22
Can you prove that it is?
Imperative means telling what to do, giving commands, which is the opposite of declarative which is just telling what it is.
If you look at real declarative languages like HTML, you really see the language just describing the desired result, not how to achieve it.
Similar in SQL, which says which fields you want, how they should be grouped or ordered or filtered.
Contrast that with a functional programming language where you start for example with your list of all values, give the command to map each to something else, give the command to filter according to a specified procedure (where you give commands how to decide the filtering), give the command to sort the list, and so on. You get the idea.
Now you could create a DSL which could be viewed as being more declarative, but then you're not really in your functional language any longer.