1. Imperative and Declarative Programming Paradigms
In the last video, we talked about the different types of programming paradigms in a general sense. In this video, we are going to dive into two broad categories of programming paradigms that will set the stage for a study of several specific, commonly used paradigms that fall within these two categories.
2. Imperative and declarative programming
In terms of programming paradigms, there are two broad categories that many of the commonly used paradigms fall under: imperative and declarative programming.
At a high level, imperative programming is a category of paradigms in which the programmer spells out the exact instructions for the program to follow, step-by-step. The focus is on how to execute the program. This style of programming paradigm could be thought of in terms of a flow chart, where the program follows a given path based on specified inputs.
Declarative programming, by contrast, is a category of paradigms in which the programmer defines the logic of the program but does not give details about the exact steps the program should follow. The focus is on what the program should execute, rather than precisely how. This type of programming is less common, but can be used in situations where the rules are clearly specified and the precise path to the solution is not known. An example might be to solve a number puzzle like Sudoku.
3. Imperative programming
Most mainstream programming languages make use of imperative programming, and two of the most commonly used programming paradigms fall under this category: procedural programming and object-oriented programming.
This category of paradigms is more common because the structure of telling the program step-by-step exactly how to execute is more similar to how a computer works, so there is less work involved to "translate" the human-readable computer code into something that is how the computer actually works internally.
Note that some people will use "procedural programming" and "imperative programming" interchangeably, but technically procedural programming is a type of imperative programming.
4. Declarative programming
Not all programming paradigms follow an imperative style, however. The other category, declarative programming, is less commonly used, but does include functional programming, which is one of the top three paradigms. Other examples of declarative programming paradigms are those used in particular programming languages that are written for very specific purposes and are not general-purpose programming languages.
5. Let's practice!
Now that we've seen some of the differences between imperative and declarative programming, and talked about some examples of paradigms in each category, let's test that knowledge with a few exercises.