Programming 101: Declarative vs Imperative Paradigm
Programming paradigm differences you should know
Paradigm means pattern or model but in the case of programming, it is a set of design principles that define the structure of a program. An app or software that is developed with a specific problem in mind, solves a specific problem. There are ways we can take to solve the problem. They both are about the way or the approach to a problem that is to be solved. There is no right or wrong, win or lose there is only one thing that is a problem is solved.
Declarative:
A declarative program tells the compiler what would you like to happen and the computer figures out the way. It lets the compiler make decisions that can result in better code. It is declarative when you say what you want.
Imperative:
An imperative program tells the compiler how to do something so that result is something that you want to happen. Or it is imperative when you say how to get what you want.
Simple yet confusing. I found an example on StackOverflow to clear things:
// 1. Declarative
var num = [1, 2, 4, 8, 16]var triple = num.map( n => {
return n * 3;
})console.log(triple) // [3, 6…