Differentiating between declarative and imperative programming
When reading the React documentation or blog posts about React, you will have undoubtedly come across the term declarative. One of the reasons why React is so powerful is that it enforces a declarative programming paradigm.
Therefore, to master React, it is essential to understand what declarative programming means and what the main differences between imperative and declarative programming are. The easiest way to approach this is to think about imperative programming as a way of describing how things work, and declarative programming as a way of describing what you want to achieve.
Entering a bar for a beer is a real-life example in the imperative world, where normally you will give the following instructions to the bartender:
- Find a glass and collect it from the shelf.
- Place the glass under the tap.
- Pull down the handle until the glass is full.
- Hand me the glass.
In the...