8 Basic Types of Programming Paradigms Available To Programmers

This post is also available in: हिन्दी (Hindi) العربية (Arabic)

What is meant by the Programming Paradigm?

In the programming world, you might have come across the term “Programming Paradigm”. Do you know what the meaning of this term is? 

The term Programming Paradigm refers to a style of programming. By style, it doesn’t mean the choice of a specific language, but rather it refers to the way you program.

There are several programming languages that programmers around the world use but all these programmers follow some specific strategy to implement the programs. This strategy that programmers follow is called a programming paradigm.

10 Best Coding Languages for Kids

Programming Paradigm Types

There are 2 basic types of programming paradigms followed by the programmers while writing their programs. These are as follows:

  1. Imperative Programming Paradigm
  2. Declarative Programming Paradigm
programming paradigm

Imperative Programming Paradigm

Imperare is a Latin word that means command. Imperative programming is the oldest programming paradigm. A program based on this paradigm is made up of a clearly-defined sequence of instructions to a computer.

In imperative programming languages, the source code is a series of commands, which specify what the computer has to do and when – to achieve the desired result. The values of the variables used in a program are changed during runtime. To control the commands, control structures such as loops and/or branches are integrated into the code.

Imperative programming languages are very specific, and operation is system-oriented. On the one hand, the code is easy to understand; on the other hand, many lines of the source text are required to describe what can be achieved with a fraction of the commands using declarative programming languages.

The imperative style is one of the oldest programming paradigms. It bears a close relation to machine architecture which is based on Von Neumann architecture. It works by changing the program state through assignment statements. It performs step by step tasks by changing state. The main focus is on how to achieve the goal. The paradigm consists of several statements and after the execution of all the statements, the result is stored in a variable(s).

Some of the best-known imperative programming languages are

  • Fortran
  • Java
  • Pascal
  • ALGOL
  • C
  • C#
  • C++
  • Assembler
  • BASIC
  • COBOL
  • Python
  • Ruby

Advantages and Disadvantages of Imperative Programming Paradigm

AdvantagesDisadvantages
Easy to readCode quickly becomes very extensive and thus confusing
Relatively easy to learnHigher risk of errors when editing
The conceptual model (solution path) is very easy for beginners to understand.System-oriented programming means that maintenance blocks application development.
Characteristics of specific applications can be taken into account.Optimization and extension are more difficult.

The different imperative programming languages are further divided into three sub-styles:

This paradigm emphasizes procedure in terms of the underlying machine model. There is no difference between procedural and imperative approaches. It can reuse the code and it was a boon at that time when it was in use because of its reusability.

Procedural Programming Paradigm

Procedural Programming may be the first programming paradigm that a new developer will learn. Fundamentally, the procedural code is the one that directly instructs a device on how to finish a task in logical steps. This paradigm uses a linear top-down approach and treats data and procedures as two different entities. Based on the concept of a procedure call, Procedural Programming divides the program into procedures, which are also known as routines or functions, simply containing a series of steps to be carried out.

Simply put, Procedural Programming involves writing down a list of instructions to tell the computer what it should do step-by-step to finish the task at hand.

Features of Procedural Programming Paradigm

The key features of procedural programming are given below:

  • Predefined functions: A predefined function is typically an instruction identified by a name. Usually, the predefined functions are built into higher-level programming languages, but they are derived from the library or the registry, rather than the program. One example of a pre-defined function is ‘charAt()’, which searches for a character position in a string.
  • Local Variable: A local variable is a variable that is declared in the main structure of a method and is limited to the local scope it is given. The local variable can only be used in the method it is defined in, and if it were to be used outside the defined method, the code will cease to work.
  • Global Variable: A global variable is a variable that is declared outside every other function defined in the code. Due to this, global variables can be used in all functions, unlike a local variable.
  • Modularity: Modularity is when two dissimilar systems have two different tasks at hand but are grouped to conclude a larger task first. Every group of systems then would have its tasks finished one after the other until all tasks are complete.
  • Parameter Passing: Parameter Passing is a mechanism used to pass parameters to functions, subroutines, or procedures. Parameter Passing can be done through ‘pass by value’, ‘pass by reference’, ‘pass by result’, ‘pass by value results and ‘pass by the name’.

Advantages and Disadvantages of Procedural Programming

Procedural Programming comes with its own set of pros and cons, some of which are mentioned below.

Advantages

  • Procedural Programming is excellent for general-purpose programming.
  • The coded simplicity along with ease of implementation of compilers and interpreters.
  • A large variety of books and online course material available on tested algorithms, making it easier to learn along the way.
  • The source code is portable, therefore, it can be used to target a different CPU as well.
  • The code can be reused in different parts of the program, without the need to copy it.
  • Through the Procedural Programming technique, the memory requirement also slashes.
  • The program flow can be tracked easily.

Disadvantages

  • The program code is harder to write when Procedural Programming is employed.
  • The Procedural code is often not reusable, which may pose the need to recreate the code if it is needed to be used in another application.
  • Difficult to relate to real-world objects.
  • The importance is given to the operation rather than the data, which might pose issues in some data-sensitive cases.
  • The data is exposed to the whole program, making it not so much security-friendly.

There are different types of programming paradigm as we mentioned before, which are nothing but a style of programming. It is important to understand that the paradigm does not cater to a specific language but to the way the program is written. Below is a comparison between Procedural Programming and Object-Oriented Programming.

Object-Oriented Paradigm

Object-oriented programming (OOP) is a programming paradigm based upon objects (having both data and methods) that aims to incorporate the advantages of modularity and reusability. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.

The important features of object-oriented programming are −

  • Bottom–up approach in program design.
  • Programs organized around objects, grouped in classes.
  • Focus on data with methods to operate upon the object’s data.
  • Interaction between objects through functions.
  • Reusability of design through the creation of new classes by adding features to existing classes.

Object-Oriented Programming comes with its own set of pros and cons, some of which are mentioned below.

Advantages 

  • A real-world idea can be demonstrated, as everything in OOP is treated as an object.
  • As we use the concept of encapsulation, programs are easier to test and maintain.
  • Faster development of code is done, as we develop classes parallel instead of sequentially.
  • OOP provides greater security due to data abstraction. The outside world cannot access the hidden data.
  • Reusability can be achieved by using classes that have been already written.

Disadvantages

  • Designing a program with an OOP concept can be tricky.
  • A programmer needs to plan for developing a program in OOP.
  • The size of programs developed with OOP is bigger than those developed with a procedural approach.
  • Since OOP programs are larger, the execution time for these programs is also more.

Parallel Processing Paradigm

Parallel computing is the use of two or more processors (cores, computers) in combination to solve a single problem. It is a type of computing architecture in which several processors execute or process an application or computation simultaneously. Parallel computing helps in performing large computations by dividing the workload between more than one processor, all of which work through the computation at the same time. Most supercomputers employ parallel computing principles to operate.

programming paradigm
Parallel Processing

This type of computing is also known as parallel processing. The primary objective of parallel computing is to increase the available computation power for faster application processing or task resolution.

Parallel computing infrastructure is standing within a single facility where many processors are installed in one or separate servers that are connected.

It is generally implemented in operational environments/scenarios that require massive computation or processing power.

Following are the advantages and disadvantages of the parallel processing paradigm.

Advantages:

  • Parallel computing saves time, allowing the execution of applications in a shorter wall-clock time.
  • Solve Larger Problems in a short point of time.
  • Compared to serial computing, parallel computing is much better suited for modeling, simulating, and understanding complex, real-world phenomena.
  • Throwing more resources at a task will shorten its time to completion, with potential cost savings. Parallel computers can be built from cheap, commodity components.
  • Many problems are so large and/or complex that it is impractical or impossible to solve them on a single computer, especially given limited computer memory.
  • You can do many things simultaneously by using multiple computing resources.
  • Can use computer resources on the Wide Area Network(WAN) or even on the internet.
  • It can help keep you organized. If you have the Internet, then communication and social networking can be made easier.
  • It has massive data storage and quick data computations.

Disadvantages:

  • Programming to target Parallel architecture is a bit difficult but with proper understanding and practice, you are good to go.
  • The use of parallel computing lets you solve computationally and data-intensive problems using multicore processors, but, sometimes this effect on some of our control algorithms do not give good results and this can also affect the convergence of the system due to the parallel option.
  • The extra cost (i.e. increased execution time) incurred is due to data transfers, synchronization, communication,  thread creation/destruction, etc. These costs can sometimes be quite large and may exceed the gains due to parallelization.
  • Various code tweaking has to be performed for different target architectures for improved performance.
  • Better cooling technologies are required in the case of clusters.
  • Power consumption is huge by the multi-core architectures.
  • Parallel solutions are harder to implement, they’re harder to debug or prove correct, and they often perform worse than their serial counterparts due to communication and coordination overhead.

Declarative Programming Paradigm

In computer science, declarative programming is a programming paradigm – a style of building the structure and elements of computer programs – that expresses the logic of a computation without describing its control flow.

Many languages that apply this style attempt to minimize or eliminate side effects by describing what the program must accomplish in terms of the problem domain, rather than describe how to accomplish it as a sequence of the programming language primitives. (the how is left up to the language’s implementation). This is in contrast with imperative programming, which implements algorithms in explicit steps.

Declarative programming often considers programs as theories of formal logic, and computations as deductions in that logic space. Declarative programming may greatly simplify writing parallel programs.

Common declarative languages include those of database query languages (e.g., SQL, XQuery), regular expressions, logic programming, functional programming, and configuration management systems.

Examples of Declarative Programming Languages

The best-known declarative programming languages are:

  • Prolog
  • Lisp
  • Haskell
  • Miranda
  • Erlang
  • SQL

Advantages and Disadvantages of Declarative Programming Paradigm

Following are the advantages and disadvantages of the Declarative Programming languages:

Advantages:

  • Short, efficient code
  • Can be implemented using methods not yet known at the time of programming
  • Easy optimization as implementation is controlled by an algorithm
  • Maintenance possible independent of application development

Disadvantages:

  • Sometimes hard to understand for external people
  • Based on an unfamiliar conceptual model for people (solution state)
  • Hard to take characteristics of individual applications into account during programming

The different declarative programming languages are further divided into three sub-styles:

  • Logic Programming Paradigm
  • Functional Programming Paradigm
  • Database Processing Paradigm

Logic Programming Paradigm

It can be termed as an abstract model of computation. It would solve logical problems like puzzles, series, etc. In logic programming we have a knowledge base that we know before and along with the question and knowledge base which is given to the machine, it produces results. In normal programming languages, such a concept of the knowledge base is not available but while using the concept of artificial intelligence, machine learning we have some models like the Perception model which is using the same mechanism.

In logical programming, the main emphasis is on a knowledge base and the problem. The execution of the program is very much like proof of the mathematical statement, e.g., Prolog.

Advantages and Disadvantages of Logic Programming Paradigm

Logic programming has its number of advantages and disadvantages, and here are some of them:

Advantages:

• Logic programming can be used to express knowledge in a way that does not depend on the

implementation, making programs more flexible, compressed, and understandable.

• It enables knowledge to be separated from use, ie the machine architecture can be changed

without changing programs or their underlying code.

• It can be altered and extended in natural ways to support special forms of knowledge, such

as meta-level of higher-order knowledge.

• It can be used in non-computational disciplines relying on reasoning and precise means of

expression.

Disadvantages:

• Initially, due to insufficient investment in complementary technologies, users were poorly

served.

• In the beginning, poor facilities for supporting arithmetic, types, etc. had a discouraging

effect on the programming community.

• There is no adequate way of representing computational concepts found in built-in

mechanisms of state variables (as is usually found in conventional languages).

• Some programmers always have, and always will prefer the overtly operational nature of machine-operated programs, since they prefer active control over the ‘moving parts’.

Functional Programming Paradigm

The functional programming paradigm has its roots in mathematics and it is language independent. The key principle of this paradigm is the execution of a series of mathematical functions. The central model for the abstraction is the function that is meant for some specific computation and not the data structure. Data is loosely coupled to functions. The function hides their implementation. A function can be replaced with its values without changing the meaning of the program. Some of the languages like Perl, JavaScript mostly use this paradigm.

Following are the advantages and disadvantages of Functional Programming languages:

Advantages

  • Because pure functions don’t change any states and are entirely dependent on the input, they are simple to understand. The return value given by such functions is the same as the output produced by them. The arguments and return type of pure functions are given out by their function signature.
  • Due to the nature of pure functions to avoid changing variables or any data outside it, implementing concurrency becomes efficacious
  • It supports the concept of lazy evaluation, which means that the value is evaluated and stored only when it is required.
  • Pure functions take arguments once and produce unchangeable output. Hence, they don’t produce any hidden output. They use immutable values, making debugging and testing easier.
  • Its style treats functions as values and passes the same to other functions as parameters. It enhances the comprehension and readability of the code.

Disadvantages

  • Immutable values combined with recursion might lead to a reduction in performance
  • In some cases, writing pure functions causes a reduction in the readability of the code
  • Though writing pure functions are easy, combining the same with the rest of the application as well as the I/O operations is tough
  • Writing programs in recursive style in place of using loops for the same can be a daunting task

Database Processing Paradigm

This programming methodology is based on data and its movement. Program statements are defined by data rather than hard-coding a series of steps. A database program is the heart of a business information system and provides file creation, data entry, update, query, and reporting functions. Several programming languages are developed mostly for a database application. For example SQL. It is applied to streams of structured data, for filtering, transforming, aggregating (such as computing statistics), or calling other programs. So it has its wide application.

Advantages and disadvantages of Database Processing languages are listed below:

Advantages:

  • Reduced data redundancy
  • Reduced updating errors and increased consistency
  • Greater data integrity and independence from applications programs
  • Improved data access to users through the use of host and query languages
  • Improved data security
  • Reduced data entry, storage, and retrieval costs
  • Facilitated development of new applications program

Disadvantages:

  • Database systems are complex, difficult and time-consuming to design
  • Substantial hardware and software start-up costs
  • Damage to database affects virtually all applications programs
  • Extensive conversion costs in moving from a file-based system to a database system
  • Initial training required for all programmers and users

Declarative vs. Imperative Programming

Imperative programming languages differ from declarative languages on one fundamental point: imperative programming focuses on the “how”, declarative programming on the “what”.

But what does that mean? Imperative programming languages are composed of step-by-step instructions (how) for the computer. They describe explicitly which steps are to be performed in what order to obtain the desired solution at the end. By contrast, in declarative programming, the desired result (what) is described directly. This becomes clearer when using a cooking analogy for illustration: imperative languages provide recipes; declarative languages contribute photos of the finished meal.

In declarative languages, the source code remains very abstract in terms of the specific procedure. To get to the solution, an algorithm is used which automatically identifies and applies appropriate methods. This approach has numerous advantages: Programs can be written much more quickly, and applications are also very easy to optimize. If a new method is developed in the future, the abstract instructions in the source code mean that the algorithm can easily utilize the newer method.

Conclusion

In practice, mixed forms of the paradigms are generally used these days because both imperative and declarative programming styles have their advantages and disadvantages. However, the declarative programming style is becoming increasingly dominant, supplemented by imperative methods.

Leave a Comment