What is Functional Programming?
Firstly, Functional programming is a programming paradigm in which everything is bound using pure mathematical functions. It’s a declarative programming approach. In contrast to an imperative style, which focuses on “how to solve,” it focuses on “what to solve.” Instead of statements, it uses expressions. A statement is executed to assign variables, but an expression is evaluated to create a value. In addition, Those functions have some unique characteristics.
Components of functional programming
- Pure functions
- Referential transparency
- Functions are First-Class and can be Higher-Order
What is a Pure Function?
Pure functions are normal functions with some characteristics :
- Total / Not Partial
- No Randomness
- No Side Effects
- Not Null
- No Exception
- No Mutation
Example of Pure Function
def add(a: Int, b: Int): Int = a + b
Example of Not a Pure Function
def divide(a: Int, b: Int): Int = a / b
The ‘divide’ function passes all the parameters of being a pure function but if in case ‘a’ will be divided by 0, Then it will throw an exception which will make it not a pure function.
Advantages and disadvantages of Functional Programming
- This programming aids in the effective resolution of difficulties.
- It improves modularity.
- It allows us to implement lambda calculus in order to solve complex problems
- Some programming languages support nested functions so it improves the maintainability of the code
- It reduces complex problems into simple pieces so that it will be easy to solve.
- It’s difficult to grasp for novices, hence it’s not a beginner-friendly paradigm approach for new programmers.
- Maintenance is difficult during the coding phase when the project size is large
- Moreover, Reusability in Functional programming is a tricky task for developers
For further information on functional programming wait for the next blog…
For more details please visit: https://en.wikipedia.org/wiki/Functional_programming