DEV Community

Jay Cruz
Jay Cruz

Posted on • Originally published at jay-cruz.Medium on

An Overview of Programming Paradigms

picture of two arrows with text more than one way

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.

Imperative

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.

Declarative

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.

Procedural

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.

Object-Oriented

The object-oriented paradigm is the one that is most widely in use today in modern Software Development. It focuses on utilizing objects, classes, and methods to store, manage, and manipulate data. The main characteristics of this paradigm that make it so applicable are the concepts of encapsulation, inheritance, abstraction, and polymorphism. This paradigm gives us a way to model our code based on the real world. It can produce applications with good scalability and security. There are many examples of object-oriented based languages. Some of the more popular ones to name are Ruby, C++, Java, and Python. Even Javascript was created originally as an object-oriented language.

Functional

Another paradigm that is quickly gaining popularity in the industry is the functional one. This paradigm is all about maintaining the application’s original state and keeping your code predictable. The core concepts of Functional programming are pure functions and immutability. Pure functions are simply functions without side effects; they don’t deliver any unexpected results. Immutability is not being able to change. Immutable values are unchangeable once they’re assigned. These characteristics of the functional paradigm make it capable of producing highly reusable, testable, safe, and efficient code. One purely functional language is Haskel. Other multiparadigm languages like Javascript also use Functional programming.

Summary

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.

Helpful resources

Originally published at https://coderjay06.github.io on May 18, 2021.

Top comments (0)