programação funcional

What is functional programming? Find out how it came about, where it’s used and more!

Written by LogAp

Although it was created decades ago, functional programming is still very small compared to other software development paradigms. However, this does not mean that it is inferior, but rather that its application is not as popular in relation to what the large development market uses.

In fact, as we will see throughout this content, functional programming has features which are essential to the creation of critical systems that need extreme quality. That has placed it on the map of big companies, which are using languages like Erlang, Elixir and Clojure to create amazing solutions.

Want to know more about this topic?

So, keep reading to find out what functional programming is, its history, features, main advantages and uses in modern software development. Enjoy!

 

What is functional programming?

Like object-oriented programming, imperative programming, and structured programming, functional programming is a paradigm of software development because it is based on the use of functions —from which its name originates.

It is important to understand that the use of the term paradigm concerns the method of performing a task.

Thus, functional programming delegates the transformation of the data to specific and complementary functions, whose objective is to do the processing and generate the expected result for a given problem.

 

How did functional programming come about?

Functional programming began long before modern computers, from a 1930s computational model called Lambda Calculus, created by Alonzo Church.

This model gave programming language Lisp life at the hands of John McCarthy in 1958 and, over time, gained popularity for its unique and positive features for software development.

Therefore, we can objectively consider John McCarthy as the father of functional programming.

 

Use cases of functional programming

In general, functional programming can be used in the development of any type of software. However, this paradigm specifically shines in some use cases:

  • When complex problem solving is required;
  • When massive data processing is required;
  • When it is necessary to multi-process;
  • When it is necessary to avoid collateral systems, especially in financial systems or manipulation of sensitive data.

 

How does functional programming work and where is it used?

The concept of functional programming is quite simple. It relies on mathematical functions to receive an input data, treat it, and return it with an expected output.

Thus, functions can be changed as needed so that the result is different from the input. However, the input data must remain constant regardless of what happens within the functions.

Another interesting point of functional programming is the absence of variables. That is, the codes will always be more objective and even easier to read, since we will always have a fixed entry with the treatment in the functions.

In order to try to make the explanation simpler, let’s propose the following example:

Imagine that you are making an apple pie, where the entry constant is the apple. The apple will be worked by the functions, responsible for transforming the fruit and, in the end, delivering the ready-to-eat pie.

In the case of functional programming, even if the apple pie is the result, we have the input element — the apple — as an immutable object. That is, to change the output, we can alter the functions, but never the initial ingredient.

We could even try to put bananas in the middle of the process, but the result produced would still in the end be an apple pie.

 

Features and advantages of functional programming

Now that you have understood, briefly, what functional programming is, let’s get to know its practical advantages through the characteristics of language:

 

  • Ease of code management: because it is shorter and more objective than other paradigms, code in functional programming is easier to understand and manage, as well as finding potential flaws and conducting testing;
  • Immutability: another advantage of functional programming is the concept of immutability, since the mathematical basis of the code always allows the same result, if the same input value is used;
  • Predictability: based on the above concept, we know that simpler code with immutable results makes the system more predictable, whereby any need for change can be performed directly within its functions;
  • Ease of parallel computing: all previous features allow different pieces of the system to run on different processors without any kind of issue.

 

These 4 features result in easier-to-manage systems, as cleaner code and ease of implementation of  automated tests result in more robust software, consistent with high operating standards.

Thus, while it is an immense challenge for those who already live off software development, the functional concept is a great recommendation for those starting out in the development world.

Do you like the content? Take the opportunity to read other technical recommendations:

LOGAP is a bespoke software company for innovative businesses.

Join our list and receive content for free!

Subscribe for a first-hand access to our bespoke content for innovative companies directly in your mailbox:

Registration successful!

You wil soon receive free content in your email.