In today's time, the technological advancements have equipped us with a wide variety of programming technologies in every field. Starting from web development to OS administration. But still, some exceptions arise in a set. And that exception, needs an exceptionally other way out of the remaining methods. Due to this set of exceptions faced. The different types of paradigms came into existence, so as to devise the best possible method for a specific set of problems.
What is a Programming Paradigm?
In dictionary language, a paradigm is defined as a way of solving a problem or doing a task. So the term 'Programming Paradigm' also becomes a bit clear now. Programming means to write a code and paradigm is a way of doing that task.
So Programming Paradigm is a way of writing a computer program, or a way of doing a task with the help of the features provided by a programming language. Like the task of washing clothes, has 2 paradigms, either washing by hand or by machine. And similarly in the case of programming, It is a way of representing a program in such a unique way that makes it much more efficient with a particular programming language. Whether by breaking the program into smaller modules or in single full fledged program.
Types of Programming paradigms
Since each programming paradigm, defines a particular way to solve a problem. Therefore, it can be considered as a important point for the classification of programming languages based on their features.
Majorly Programming paradigms are of 2 types: Imperative Programming paradigm and Declarative Programming Paradigm. These 2 have further sub-categories as shown in image below.
Imperative programming paradigm
Imperative programming paradigm is a paradigm of computer programming in which the sequence of steps are defined to change the state of computer or to do different tasks in a computer. It is one of the oldest programming paradigm based on the Von Neumann architecture. A step by step procedure is followed to change the computer's state. It focusses on only the completion of the task or on describing how the program operates, without specifying how the goal is achieved.
Different types of imperative programming languages are: C, ada, ALGOL, D, C++, C#, FORTRAN, Go, Python, Ruby, Rust etc.
Advantages of using imperative programming paradigm:
- It is the easiest paradigm to read and learn.
- Contains only fundamental basic implementations like loops and variables etc.
- Beginner friendly paradigm
Disadvantages of using imperative programming paradigm:
- Code becomes very lengthy and confusing.
- Optimization and extending the code is even more difficult.
- More error prone.
Sub-categories of programming paradigms in Imperative paradigm:
1. Procedural programming paradigm
Procedural programming paradigm is a type of Imperative programming, which emphasizes on the procedures/instructions which are given to the computer to carry out computations. It is derived from structured programming. In Procedural programming, during the execution of a program, any procedure can be called at any time. It is near about similar to its parent paradigm, i.e. Imperative programming.
It is also known as Event-driven programming.
Different procedural programming languages are C, C++, Java, FORTRAN, BASIC etc.
Advantages :
- It enables easy communication between software and sensors.
- Excellent for general purpose programming.
- Easily trackable program flow
- Portable source code
Disadvantages :
- Difficult to remember
- No hierarchy in code
- No security of data; data is exposed to the whole program
- Difficult to relate with real world entities.
2. Object Oriented programming paradigm
Object Oriented programming or OOP paradigm is the most latest paradigms invented, which is based on the concept of real-world entities known as objects, which contain data and code in the form of attributes and procedures, in an encapsulated form. Object Oriented programming paradigm has 4 main features: Polymorphism, Inheritance, Encapsulation and Abstraction, which makes it even much easier to understand the general paradigm.
Several Object Oriented Programming languages are C++, Java, C#, Python, Ruby, Perl etc.
Advantages :
- Code reusability
- Scalability
- Flexibility in Programs
- Modularity
- Functions cannot directly access the data: hence, data is secure
Disadvantages :
- It tends to use more CPU
- Can cause duplication
- Steep learning curve
- Little bit complex to learn the concept of objects, how they communicate with eachother etc.
Declarative programming paradigm
Declarative programming technique is such a paradigm, in which the code is written in such a order that the logic of computation is clearly visible to the user, without describing how the program operates. It is a very high level paradigm that clearly describes what a computation should perform. It basically focuses on the output, unlike Imperative programming which focusses on the procedures which lead to output.
Declarative programming languages : SQL, XQuery, Prolog, Haskell, Miranda, Erlang, Lisp etc.
Advantages :
- Code is short and efficient
- Easily Optimizable code
- Readability and Reusability
- It minimalizes mutability
- Reduces state-side effects
Disadvantages :
- Sometimes it becomes difficult to understand for some people
Sub-categories of programming paradigms in Declarative paradigm:
1. Logical programming paradigm
A formally logic based programming paradigm to solve problems like puzzles, series etc. The program written by logical programming paradigm, is a set of instructions in logical form describing the facts and rules about the problem. The rules are written in form or clauses. Here the main emphasis is on the basic knowledge of the user and the given problem.
Logical programming languages : Prolong, XSB, Mercury, Oz etc.
Advantages:
- Reliable
- Quick development of programs
- Only good knowledge base is required
Disadvantages :
- Slow program execution
- Cannot solve all problems, as logical programming uses majorly if-else statements
2. Functional programming paradigm
Functional programming paradigm is a type of declarative programming, in which programs are constructed using functions, mostly trees that return values. Here, functions are treated as first-class citizens. It has its roots in academia or mathematics. It is also considered as purely functional programming, which is a subset of functional programming which treats functions as deterministic mathematical functions or pure functions. The data also is loosely coupled with functions and their implementation is also hidden.
Functional programming languages: ML, Clojure, Haskell, JavaScript, Scala, Lisp etc.
Advantages :
- Debugging is easier
- Testing is easier
- Higher level programs thus easier to comprehend
- Bulletproof programs
- Powerful abstraction
Disadvantages :
- The I/O relies on the side-effects, so it inherently non-functional
- Non-functionality of computers
- Difficulty in representing a state in functional programming
-------------------------------------------------------
Since, there are large number of paradigms available, do mention other programming paradigms that are also useful in the comments.