Introduction to Programming Paradigm- Unlocking the basics

Pinki Singh
4 min readMay 1, 2024

Hello everyone, In this article we are learning about Programming paradigms. I know you may think why it is important or we all know the basics of programming, yes you are right we all know it, but my reason to write this article is when we read “programming paradigms”, we judge it as easy but there is a lot things a beginner should know or a experience developer must know about this. And this is important in order to understand any programming languages and how our computer runs program and how our code works and what is the type of our programming language. Without wasting time Let’s Start.

What are Programming Languages? Why it is needed?

Programming languages are just a language which understand by a computer. It allows us to convert our idea or operations in written format the way so computer can understand it. As we all know machine only knows 0 and 1, But it is difficult to write our tasks or operations in 0’s and 1’s so, we need a human readable language, And to rescue us from this problem there are so many programming languages hence now we can give instructions to our CPU and yes it can print output for us. Internally computer covert those instructions in bunch of 0’s and 1’s.

What is Programming Paradigm?

Programming paradigm is a technique, a method and a strategy of writing programs in a particular programming language to address a specific problem . There are several types of programming paradigms but here we discussed only two main programming paradigm.

  • The paradigm of imperative programming
  • The paradigm of declarative programming

Let’s deep dive into these programming paradigm:

The Paradigm of Imperative Programming:

Imperative Programming Paradigm that focuses on describing how a program operates. Programs are written in well describing format. Developer explicitly describes all the steps that is needed to achieve an outcome.

Moreover, this paradigm depends heavily on control structure such as loop(while loop, for loop) and conditional (if-else) flow to direct program flow. And it is because its main focus on “How” approach. These structures dictate the order in which statements executed. Developers must describe how to perform a task in detail, including low-level operations and algorithms.

For Example: Suppose we want to multiply all the arrays element with 2, and print it.

let arr = [1,2,3,4,5];
let multiplyArr = [];
let n = 2;
for(let i=0; i<arr.length; i++){
multiplyArr.push(arr[i]*n);
}
console.log(multiplyArr); //output [ 2, 4, 6, 8, 10 ]

In the above example, we are describing all the needed steps which is required to get a desired outcome.

I am going to mention two subcategories of imperative programming:

  1. Procedural Programming Paradigm: Procedural programming is identical of imperative paradigm. This programming paradigm mainly focuses on writing procedures and routines that perform operations on data. In this, Programs are divided into a set of functions and procedures so it can execute to complete the task. All the procedures are executes top to bottom in a sequential way.
  2. Object-Oriented Programming paradigm: As it’s name said “Object-Oriented” It means it revolves around objects, Objects are the real world entities and we can use it to create classes which is very helpful in maintaining clean code structure.

The Paradigm of Declarative Programming:

Declarative Paradigm of programming, mainly focuses on describing the desired outcome or result, rather than specifying the exact steps needed to achieve that outcome. Developer does not explicitly mention that how to perform a task, The developer simply declares what they want to achieve.

Moreover, In this paradigm developer create objects or programming components to achieve desired outcomes. These objects or functions encapsulate the logic needed to achieve desired results and the underlying system or framework is the one who determine how to perform a task and achieve desired results efficiently and allowing the developers to focus on high-level concepts rather than implementation details.

For Example: Suppose we want to multiply all the arrays element with 2, and print it.

let arr = [1,2,3,4,5];
let multiplyArr = arr.map(number =>
number*2
);
console.log(multiplyArr); //output [ 2, 4, 6, 8, 10 ]

In the above example, we use the map function, which applies a function to each element of the arr array and returns a new array with the results. We simply declare what transformation we want to apply to each element, without specifying how it should be done.

I am going to mention two subcategories of declarative programming:

  • The paradigm of logic programming: In this programming, words are constructed logically, and symbols are used to construct an expressions to get the desired outcome.
  • The paradigm of functional programming: In this programming, most of the code is written by constructing functions and each function perform a specific task and complete the original task. In this developer basically define a function and their work to get output from it. It is helpful when someone wants to perform same task on different places then we only need to call the function.

Conclusion:

Both Paradigms have their own advantage and disadvantage. You can choose paradigm according to the work you want to perform.

In declarative paradigm, it provides better maintainability and readability of the codebase but developer has less control over task execution, specially in complex scenario.

In Imperative programming, It provides procedures so it helps beginners to understand the code flow and allowing for more flexibility in handling complex scenarios because developer has control on the execution flow. Code tends to be longer and more verbose, which can make it harder to read, understand, and maintain, especially as the codebase grows larger.

That’s all from my side! If you have any suggestions or feedback feel free to reach out. If you want me to write on a specific topic just mention you topic in comments.

Let’s connect on LinkedIn: https://www.linkedin.com/in/pinkisingh23/

Thank you for reading until the end. Before you go:

Please consider clapping and Don’t forget to follow me! 👏.

--

--

Pinki Singh

Passionate Flutter dev crafting delightful experiences. Familiar with Java & JavaScript. Learning Node.js. Let's connect: www.linkedin.com/in/pinkisingh23