Functional Programming (FP) was developed for functional application, definition, and recursion in the 1930s.
History of Functional Programming:
The first functional programming language was LISP. It was designed by McCarthy in 1960.
At the University of Edinburgh, researchers defined the ML (Meta Language) in the late 70s. For recursion and equation reasoning, Hope Language adds algebraic data types in the early 80s.
In 2004, Functional Language Scala was invented.
Functional Programming Paradigm
FP is a way of thinking about software development by writing pure functions. This programming paradigm avoids the concepts of mutable data and shared state as we observed in OOP.
FP emphasizes on declarations and expressions instead of execution of statements.
In FP, output depends only on the arguments passed to the function unlike other procedures that depend on local or global data.
There are two categories of functional programming languages:
- Pure functional languages that support only functional paradigm e.g. Haskell.
- Impure functional languages that support both functional paradigm and imperative paradigm e.g. LISP.
Features of functional programming
The method does not focus on the process. It focuses on results. Here, the emphasis is on what is to be computed.
In the FP paradigm, the whole problem is decomposed into functions. It does not support conditional statements like if-else and iteration statements like for-loop, while-loop, etc. It uses functions and function calls directly.
To perform calculations, functional programming uses conditional expressions and recursion as it is based on the concept of mathematical functions.
Like object-oriented programming, FP languages support encapsulation, inheritance, polymorphism, and abstraction concepts.
Functional Programming vs. Object-Oriented Programming
Functional programming supports parallel programming. It focuses on what you are doing. Its functions have no side-effects. This paradigm follows the declarative programming model. To iterate collection data, it uses the recursion concept. In FP, the execution order of statements has no importance. It uses immutable data.
On the other hand, object-oriented programming is not suitable for parallel programming. It focuses on how you are doing. OOP methods can produce serious side-effects. This paradigm follows the imperative programming model. To iterate collection data, it uses loops. In OOP, the execution order of statements is very important. It uses mutable data.
In Functional Programming, flow control is achieved using functions and function calls. Whereas: OOP flow control is achieved using conditional statements and loops.
Functional Programming supports both “Abstraction over behavior” and “Abstraction over data” concepts. While Object-Oriented Programming supports only the “Abstraction over data” concept.
The efficiency of a FP Code
Following factors affect the efficiency of a program:
- Speed of compiler
- Operating System
- Speed of computer machine
- An algorithm that was used to solve the problem
- The way in which program data is organized
Normally, the efficiency of a program is directly proportional to the efficiency of the algorithm used and execution speed. Good efficiency means higher performance.
Following tasks can improve the efficiency of a programming language:
- Remove the code that causes redundant processing
- Remove the unnecessary code
- Use reusable components where applicable
- Use exception handling methods
- Write programming code that ensures data consistency
- Write programming code that ensures data integrity
Resource consumption and completion time can be reduced by using an efficient programming code.
Here is a list of some prominent functional programming languages:
Functional programming concepts and terminologies
What is immutable data? It means you will be able to create data structures easily instead of modifying the existing ones.
What is referential transparency in FP terms? It means a functional program should perform operations as if it is for the first time. Thus, you may able to know what may and may not happen during program execution.
What is modularity? It means a functional program can be divided into smaller parts called modules that make coding easy and leads to faster software development.
Modular design increases productivity. Each module can be tested separately that ultimately reduces the time spent on testing and debugging.
What is a closure? In FP terms, a closure is an inner function that can access variables from the parent’s function; even after parent function is executed.
Advantages of functional programming paradigm
Functional programing supports nested functions. It allows effective use of Lambda calculus. It gives the developer increased productivity. FP code can be easily tested and debug.
Functional programming gives concurrency and parallel processing. It gives better modularity with shorter code. It gives functional constructs like Lists and Lazy Maps etc.
FP provides fault tolerance and hot code deployment. It also allows you to avoid errors in code.
Limitations of the functional programming paradigm
This paradigm is not easy. So, it is difficult for beginners to learn the paradigm. During the coding, many objects are evolved. That’s why it’s hard to maintain FP code.
To create an FP code, you may need an extensive environmental setup. To re-use FP code, you may need constant re-factoring and hence it becomes complicated to apply the re-usability concept on FP code.
The purpose of any functional programming language is to copy the mathematical functions.
In FP, the concept of a pure function is used. A pure function is one in which nothing should be hidden. Inputs are declared as inputs and outputs are declared as outputs.
Side-effects: such as triggering any external process, writing to the network or file, logging to the console, etc. are mostly avoided in functional programming that makes the program easier to understand and test.
Furthermore, it supports the concept of higher-order function. It is a function that takes any other function as an argument and returns a function. It is used to create utilities that work on a variety of data types.
Let’s have a look at some other MAJOR Programming Paradigms in detail:
Subscribe to FinsliQ Blog:
If you have enjoyed and find our blogs informative, then please support the platform by subscribing to our daily newsletters. Benefits of becoming a subscriber:
- Get daily updates with the latest blogs/article
- New updates within the same subject area are release every day (release dates can be found next to the link in the blog)
- Stay up to date with the latest Tech news
- Variety of different types of blogs
Visit FinsliQ | Tech Academy. A variety of course are available in cloud computing, Dev-ops, Cloud Architecture, Cyber Security and much more.