The benefits of functional programming

In this note I will talk about the many benefits of functional programming:

  • Functional programs are easier to reason about because they’re deterministic. One specific input will always give the same output. In many cases, you might be able to prove your program correct rather than extensively testing it and still being uncertain whether it will break under unexpected conditions.
  • Functional programs are easier to test. Because there are no side effects, you don’t need mocks, which are generally required to isolate the programs under test from the outside.
  • Functional programs are more modular because they’re built from functions that have only input and output; there are no side effects to handle, no exceptions to catch, no context mutation to deal with, no shared mutable state, and no concurrent modifications.
  • Functional programming makes composition and recombination much easier. To write a functional program, you have to start by writing the various base functions you need and then combine these base functions into higher-level ones, repeating the process until you have a single function corresponding to the program you want to build. As all these functions are referentially transparent, they can then be reused to build other programs without any modifications.

Functional programs are inherently thread-safe because they avoid mutation of shared state. Once again, this doesn’t mean that all data has to be immutable. Only shared data must be. But functional programmers will soon realize that immutable data is always safer, even if the mutation is not visible externally.

 

Вас заинтересует / Intresting for you:

Learning Programming Terminolo...
Learning Programming Terminolo... 2490 views Antoni Sun, 13 May 2018, 18:12:05
Clustering Basics: scalability...
Clustering Basics: scalability... 3083 views Семен Thu, 18 Jun 2020, 17:12:58
Relational Model and Why It Ma...
Relational Model and Why It Ma... 2256 views Александров Попков Sat, 18 Jul 2020, 19:28:38
Relational Versus Document Mod...
Relational Versus Document Mod... 6807 views dbstalker Fri, 04 Oct 2019, 06:16:32
Comments (0)
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Suggested Locations