Build your future, learn coding!     |        50% OFF courses and career paths     |        Limited Time Only

close
Cart icon
User menu icon
User icon
Lightbulb icon
How it works?
FAQ icon
FAQ
Contact icon
Contact
Terms of service icon
Terms of service
Privacy policy icon
Privacy Policy
Zdjęcie główne artykułu.

Programming paradigms - what are they?

The word paradigm can sound threatening, but it shouldn't. There's nothing terrible or complicated here. So what exactly is this paradigm?

It is nothing more than a certain "style" of programming, or in other words: an approach to problem solving. You can think of a paradigm as a certain set of rules used when writing programs.

There are different programming paradigms. Each of them has its pros and cons. Choosing the right one is dictated by many factors:

  • programming language;
  • the complexity of the software we write;
  • the complexity of the problems we need to solve.

In this article you will learn the most popular programming paradigms. You will discover what their features are and in what situations they are used.

Procedural programming

This paradigm is about writing code as a set of sequential instructions (procedures) for the computer to execute. Imagine that you are writing a program to calculate the area of a rectangle. We will break it down into individual procedures:

  1. Get the length of side a and b
  2. Calculate the area of the rectangle
  3. Display the calculated value of the area

So we have three simple instructions/procedures that are executed in a sequence. We could say that the code of such a program gets executed " from top to bottom".

This approach to programming has its advantages: it is simple to understand and, in many situations, completely sufficient for writing a program. This is the paradigm from which we usually start learning programming.

This approach also has its drawbacks. Procedural programming is not an ideal choice for large, complex applications. This paradigm generally hinders a modular approach to writing the code.

Object-oriented programming

Another very popular paradigm is object-oriented programming. It is based on classes and objects. Using them we define components that can be used repeatedly.

The main advantage is that such components resemble structures from the real world around us. Imagine that you are writing a program to manage orders. Using the object-oriented programming paradigm, you can create:

  • A class that represents orders.
  • Properties that represent information such as order value, order date, status, etc.
  • An object that represents a single order.

As you can see this approach is very intuitive. Because instead of procedures we use structures that we understand.

An object-oriented approach makes sense for complex applications that need to be developed, improved, and extended on a regular basis.

Of course, there are also some challenges. In general, object-oriented programming is more complex than procedural programming. It requires the programmer to have more experience. It requires good planning of the program structure.

Functional programming

Functional programming has become very popular in recent years. In this paradigm, functions are the fundamental building blocks of the program structure.

A function could be described like this: input data -> data processing -> output data. Each function does only one thing. If you want to perform more complex operations then you perform what is called composition. In other words, you take the data returned by the function and pass it to another function, which performs another operation on it.

This approach has its advantages. Programs written in a functional manner are easy to test. It is also easy to write larger program blocks using basic functions.

Of course, as usual, a lot depends on the experience of the programmer. Functional programming has its own requirements. It requires the right mindset and the right approach to writing the code. The functional approach is based on mathematical foundations and for this reason it is often quite difficult to understand, especially for novice programmers.

Important Notes

The paradigms you already know from this article are not the end of the topic. We simply focused on the most popular ones.

Keep in mind that this is not a zero-sum choice. In practice it is hard to write a complete program based strictly on one paradigm. In case of complex applications it is often the case that some parts are based on, for example, functional approach but other parts are written in object-oriented manner. Or we have a program based on the object-oriented approach with some procedural elements. This is a normal and very common situation.