Imperative vs Declarative
Imperative code is code that tells the machine what to do and how to do it. VS Declarative code is code that tells the machine what to do and what should happen. Computer needs imperative code instruction - detailed step by step on what to do. On the other hand, humans are more declarative, for example, asking someone for water. Another examples of imperative are for-loop and jQuery and declarative are for-each and React.
Functional programming helps us to be more declarative by using functions and what we'll learn eventually is composing functions where we tell our programs what to do, instead of how to do it. When we talk about declarative and imperative, declarative code is always going to end up, either compiled down or being processed by something imperative like machine code. But, the idea is for us to go a level higher into declarative code, so that it's easier to read and we can be more productive.
Last updated