Advantages and Disadvantages of Functional Programming

Learn about the advantages and disadvantages of functional programming in this lesson.

Advantages of functional programming

Here are the main advantages of functional programming:

FP often creates less code

This is because it tends to work at a slightly higher level than the other paradigms, so it achieves more with each line of code.

Intent of the code is clearer

For example, if you use map to apply a function to a data stream, the meaning is clear and unambiguous. However, if you define a procedural function that loops over the data and applies the function, you need to read and understand the code to check exactly what it is doing.

There are often fewer bugs

Using standard functions that are well tested, instead of ad hoc loops that might contain bugs, is generally more reliable.

Code is potentially mathematically provable

If your program consists entirely of predefined functions that are known to be correct, and you combine those functions using higher-order functions that are also known to be correct, and if you have eliminated all side effects, then it is possible, at least in principle, to prove that your code will be correct in all cases.

Multiprocessing can be applied easily

For example, if you are applying a pure function to a data stream, you can safely split that data stream into several blocks and process each block in a different thread or even on a different computer and in any order. The map-reduce pattern does this very effectively. However, if you have a procedural program that works on lists of data, multiprocessing can often be more difficult and error-prone.

Get hands-on with 1200+ tech skills courses.