Learn more about Functional Programming for applications

Tram Ho

What is Functional Programming?

Functional Programming has been around for a long time, it’s the main programming platform. As technology has evolved, other programming languages, such as SML, OCaml, APL and Clean, have left FP lagging behind, although still being developed but used only for academic purposes and The research is mainly. This raises the question of why FP has been present for a long time and still maintained its development, but FP has not achieved as much success as, Imperative or OO …

FP is a fairly popular and important programming method in computer science. FP’s job is to see the program as a collection of functions that take arguments and return values. Unlike imperative and OO, FP does not produce side effects and uses recursion instead of loops. The function of FP is very similar to the function in mathematics because it does not change the state of the program.

For example: f (x) = y, then x will always be equal to y, the quantity when it is assigned the value never changes that value.

The mathematical basis of FP is very transparent, so because it is not flexible in state changes, FE provides a logical and concise solution to computational problems. Therefore makes people prefer other paradigm to handle common computing operations. With F #, the above barrier is solved because it allows to use multiple paradigm and mix them together to solve the problem in the most convenient way.

The terms in FP are as simple and clear as they are. To gain an overview of this industry, we must first understand the concepts of it.

Pure function

A pure function of FP that consists of the same inputs, always produces the same output and certainly has no side effects.

Function composition

This is the act of performing a process that combines two or more functions to create a new function or perform a task. If you can use the function composition smoothly, it will be an important step to understand how the software is built using Functional Programming.

Shared state (Shared variable)

A shared state is generally understood as whether any variables, objects, or memory spaces exist within a shared scope. A shared scope includes the global scope and the scope closure. They are shared in so many places and it’s hard to know which function changed that variable. Functions should not be shared between variables and data. The results may vary if we change the order of the functions with shared variables.

Disadvantages of FP?

Although the way FP works is quite simple, when combined into a large program, it is very difficult: All functions must follow the same pattern, otherwise FP will catch all errors and cannot operate.

It is understandable that FP is a difficult problem, it will come with advanced math concepts: this will be a frustrating reason when you learn it. When you decide to follow functional programming, you will have to familiarize yourself and master recursive (recursive), instead of for, while using as when doing OOP. Therefore, optimizing memory when using recursion is a point to note. But this can be greatly reduced by using tail recursion.

Share the news now

Source : Viblo