Programming Paradigm - A way to program computers


You would have come across the term programming paradigm multiple times, but never understood what it really means. In this article, we have explained what programming paradigm in a detailed but simple way. You will also get to know about a lot of different programming paradigm.

Programming Paradigm

When you read about the programming paradigm on Wikipedia it says:

Programming paradigms are a way to classify programming languages based on their features

But this does not clarify what it is. Let's see what the programming paradigm actually means.

programming paradigm

A programming paradigm is a way, an approach, a style by which we write programs in a specific programming language to solve some problem.

You may be thinking what style or approach are we talking about. It is the approach creation of objects and creating programs in object oriented programming or solving problems with series of functions in functional programming or a style of creation of logic by series of symbols in logic programming.

If a programming language support or falls under a certain paradigm then this means it has some unique feature or it follows a certain approach that makes it best to solve a certain kind of problem.

For example:

A good programming language should support multiple paradigms because different programming problems require a different way to approach. If a programing language support only one or two paradigms then it may not be sufficient or contains feature required.

programming languages and paradigm

Most modern languages support are multi-paradigm languages like C++, C#, Python, Go, etc.


Types Of Programming Paradigms

The programing paradigms are categorized in multiple categories yet most significant are only two:

  1. Imperative programming paradigm
  2. Declarative programming paradigm
types of programming paradigms

1. Imperative programming paradigm

The imperative programming paradigm is the oldest paradigm and follows the most basic idea of programming. The programs in these paradigms are executed step by step by changing the current state of the program.

An imperative program consists of some command that computer operates and change the state of the program.

Imperative programming mainly focuses on how a program operates, unlike declarative programming which focuses on what the result of the program is going to achieve.

Some of the programming languages that support the imperative paradigm are:

Code example: In the example below there is a code of language supporting imperative programming, it's a C++ code. See how does it change the state of the program and has a very clear step reach to the goal.

#include<stdio.h>

int main() {
  int result = 0;
  for (int i = 0; i < 10; i++) {
    result = result + i;
  }
  printf("Result = %d", result);
  return 0;
}

The paradigm follows the Von Neumann architecture statements and consist of multiple statements and variable which calculates and stores the result.

Examples of imperative programming are Object oriented programming, procedural programming, etc.

Advantage Disadvantage
Simple to implement and manually visualize Unable to solve complex problems
Use of control flow statements Programs can't execute parallelly
Easy to read and learn Less productive, can't difficult to tackle modern day problems
More risk of error

The imperative is broadly divided into 3 subcategories:

  1. Procedural programming paradigm

    It is the same as imperative programming but with a procedure call that lets you reuse the code. And this feature was an amazing advancement at that time. Example C, C++, Java, etc.

  2. Object Oriented Programming (OOP)

    This is used to work on real-world entities in form of class and objects. Class is the blueprint of the object and you can replicate as many as the object you want. These classes contain some properties and method which all are replicated in objects. Example C++, Python, etc.

  3. Parallel processing

    In this type of programming, a program is processed by dividing it into multiple processors. The system contains multiple processors to solve the problem in less time.


2. Declarative programming paradigm

A declarative programming paradigm are those paradigms in which the programmer describes the property of the result without focusing on how to achieve it (imperative programming focuses on how to achieve the task by changing the state of the program).

The approach of this programming is to create some object or elements within the program.

The main focus in this kind of programming is what is to be done rather than how it should be done.

It does not talk about the work process of the result and only describes what the program must accomplish.

Declarative programming is used in programming languages used in a database query, regular expression, functional programming, logical programming, etc.

Some of the programming languages that support the declarative paradigm are:

Code Example: In the example below there is a code of language supporting declarative programming, it's an SQL code. See how does it talk about selecting a specific book without focusing on how to achieve it.

SELECT * FROM Books
         WHERE Category='Programming'
         AND language='english';

Declarative programing can further be subcategorized into 3 main categories:

  1. Logic programming paradigm

    Logic programming uses sentences in logical form and creates an expression by using symbols.

    In machine learning and artificial intelligence, there are many models that use these programs..

    The programs are executed very much like some mathematical statement. It is mainly based on forming logic.

  2. Functional programming paradigm

    Functional programming is the programming in which a program is constructed by creating and using functions.

    Rather than a series of statements functional programming use function to map and change one value to another value.

    Functional programming is the key feature of JavaScript.

    const sumOfSquaresOfEven = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                               .filter(num => num % 2 === 0)
                               .map(even => even * even)
                               .reduce((x, y) => x + y);
  3. Database programming approach

    This programming is based on enquiring data, its modification, its movement, etc. The most famous programming language that supports this is SQL.


Popular language and programming paradigms they support

Here are the list of programming languages and the programming paradigms they support.


FAQ Programming paradigms

  1. Q1. What is meant by programming paradigm?

    A programming paradigm is a style of programming in any programming language. It is also used to classify programming languages on the basis of paradigms.

  2. Q2. What are the 4 programming paradigms?

    The 4 programming paradigms are: Procedural, Object-Oriented, Functional and Logical

  3. Q3. What programming paradigm is SQL?

    The programming paradigm supported by SQL is declarative programming.

  4. Q4. What paradigm is C?

    The programming paradigm of C is a procedural paradigm.


Conclusion

The most commonly used term while learning about Object oriented programming is a programming paradigm, it is used for a programming language for defining its style of programming. It is commonly categorized into 2 categories: imperative and declarative paradigms. There are also other categories paradigms are divided into but they not much famous.