Popular Paradigms of Programming Easily Explained

A programming paradigm is a set of principles, methods, and concepts that define the way of designing programs. Different popular programming languages belong to different paradigms, each of which provides the coder with certain advantages and disadvantages. There are also multi paradigm languages that can be used to write programs in this or that style.

In this post, we are going to review some of the popular programming methodologies. You will learn about the pros and cons of each paradigm and how to choose one to use on your project.

Object-oriented programming

OOP represents the program in the form of interacting objects. This approach completely changes the style of programming, it consists of mapping physical objects of the real world to the software environment. It is more convenient to work with objects and more natural than traditional data transformation procedure constructs such as structural programming and imperative programming. An OOP-object is a collection of state variables and related methods (operations) that determine how an object interacts with the surrounding world. An object consists of the following three parts: name object, state, methods.

Another fundamental OOP concept is class. A class describes properties and methods that define the behavior of the objects that belong to this class.

Basic control/abstraction mechanisms:

• Object;

• Class;

• Class/object hierarchies;

• Polymorphism.

Pros: 

  • The properties of OOP make it more intuitive.
  • Many high-level programming languages are OOP languages.
  • The majority of IT companies use OOP so it is the most wide-spread approach to software development. 

Languages: C++, Java, Python, JavaScript, Objective-C.

Functional programming

Every introduction to functional programming starts with the statement that the program is represented in the form of a set of clean functions that generate results based on input data. This type of programming operates with functions in their mathematical sense. While it is claimed by many that functional programming languages are harder to learn due to their high level of abstraction, in practice functional programming provides many benefits.

Functional programming is generally used for tasks where safety and security are important. Programs written in FP languages have less bugs, do not have memory-related problems like many OOP programs do, and are able to support high load activities.

Basic control/abstraction mechanisms:

  • Pure function as the first-class object;
  • Function call (including recursive function call);
  • Lexical context, closure;
  • Lambda calculus;
  • Lazy evaluations.

Pros:

  • Functional programming languages are more abstract and the programmer focuses on more high-level tasks instead of describing procedures.
  • Amazing possibilities for parallel computing and easy refactoring due to the use of pure functions. 

Languages: Haskell, Agda, TypeScript, Lisp, Scala.

Imperative programming

This style of writing code provides the machine with the instructions about what it is supposed to do. This is one of the oldest programming paradigms which allows us to compute low-level operations such as assemblers.

An imperative program reminds of giving orders, expressed by the imperative mode in natural languages. The operations are usually performed sequentially. 

In the imperative approach to coding (as opposed to the functional approach), assignment is widely used. The presence of assignment operators increases the complexity of the computation model and makes imperative programs prone to specific errors that are not encountered in the functional approach.

Basic control mechanisms/abstractions:

  • Sequential execution of commands;
  • Branching;
  • Unconditional jump;
  • Calling a subroutine.

Pros: allows to write low-level commands for the machines.

Languages: Basic, Algol, Smalltalk, Simula.

Structured programming

According to the principle of modularity, the program is divided into separate semantic parts (modules). Each module is a functionally complete part of a program. For example, a module for finding the sum of the elements of a series. 

Each module is programmed separately, and then the modules are combined into a single program. A module in other programming languages equals a function or procedure.

Basic control/abstraction mechanisms:

• Sequential execution of commands;

• Branching;

• Cycle;

• Calling a subroutine;

• Lexical context.

Pros: 

  • Structured programming makes the text of the program more understandable – the solution algorithm is clearly visible from the source text. 
  • Subroutines allow you to replace ordered blocks of commands in the text of programs, which is why the program code becomes more compact.
  • A structured approach allows for more comprehensible and easy-to-read programs, simplifies their testing and debugging.

Languages: Basic, Pascal, JOVIAL, Cg.

You might also like to read Is a Coding Bootcamp Right For You?

Other popular programming paradigms

Metaprogramming 

Metaprogramming is a type of programming that generates other programs as a result of their work (in particular, at the stage of compilation of their source code), or programs that change themselves during execution (self-modifying code). The first allows you to get programs spending less time than if the programmer wrote them entirely by hand, the second allows you to improve the properties of the code (size and performance).

Logic programming 

Logic programming is a programming paradigm based on automatic theorem proving, as well as a section of discrete mathematics that studies the principles of logical inference of information based on given facts and inference rules. Logic programming is based on the theory and apparatus of mathematical logic using the mathematical principles of resolutions.

The most famous logic programming language is Prolog.

Procedural programming

Procedural programming is programming in an imperative language where sequentially executed statements can be assembled into subroutines, that is, larger integral units of code, using the mechanisms of the language itself.

Procedural programming is a reflection of the traditional computer architecture that was proposed by von Neumann in the 1940s. The theoretical model of procedural programming is an abstract computing system called a Turing machine.

Conclusion

Many different coding styles exist that help programmers to deal with various problems. The paradigm of programming should be selected based on the task. Choose object-oriented programming if you are working on a project with a large OOP-based codebase. Select functional programming if you want to build a program that is reliable and secure. Imperative programming should be used where there is a need to write instructions for the computer that should be executed in order. Structured programming streamlines writing compact and fast code. 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.