A programming paradigm is a style or pattern in which we choose to follow for how to structure and approach our programs and applications. There are many different paradigms that most of us are probably not familiar with. Paradigms like Stack-oriented or Concatenative just to name a few. The more common paradigms that are generally in use today are the ones that you’ve most likely implemented yourself at some point, Procedural, Object-oriented, and Functional. Each of these can be considered a subset of one of the more broad types of paradigms, imperative or declarative.
The imperative programming approach can be described as, following a series of steps in a sequential order to complete a task. Programming imperatively is telling the computer exactly how to do something. It’s similar to writing out a recipe step by step or following a morning routine like making coffee.
As opposed to imperative, declarative programming can be defined as telling the computer what to do instead of exactly how to do it. It’s a way to abstract away the detailed steps of an algorithm and focus on describing the logic to get the result. An example of a language that implements declarative programming is SQL.
The procedural paradigm is the one most programmers including myself start out with. It implements the simpler approach to managing your program's state by using global variables and uses loops to iterate over data. When programming in this paradigm you’re usually creating some sort of routines and subroutines that will eventually be called. Procedural code is evaluated in a top to bottom manner and is of the imperative type. A good example of a procedural language is C.
Selecting which paradigm to use usually depends upon the task at hand and what problem you’re trying to solve, as they all have their use cases. The imperative style might make more sense for you if you’re only looking to write a small program and you’re not too worried about changing the program’s state. The object-oriented approach could be a good choice for larger applications that change over time. The functional paradigm might be a better solution if you’re prioritizing testing, security, and keeping the application’s state intact. Or even a combination of all of these paradigms could be a better solution.
- Introduction to paradigms
- 4 Programming Paradigms In 40 Minutes
- Programming Paradigms — Computerphile
Originally published at https://coderjay06.github.io on May 18, 2021.