Functional oriented programming functions are like mathematical functions
for example, f(x) = x+3 is a function.
For any given value of x the result will always be a constant value. That is, if value of x is 3 then we can write the above equation as
f(3)=3+3, which is equal to 6
6 is a constant value. similarly for f(5) the result will always be 8. so functional oriented programming is the programming paradigm where the functions behave like mathematical functions.
One of the basic characteristics of functional oriented programming is immutability, which means once you create a variable ( var x=50; ) and its value is immutable for its lifetime. Now you will ask that, how I change the value. If it is needed to change the value, you create another variable with the modified value ( var y = x+20; ). In this case in the showned in the bracket, you can see that ‘x’ remains unchanged.
what is the benefit of this, it makes programing easy in a multi-threaded and multi-core environment without any side effects.
functions in functional oriented programming are called first-class citizens, which means they can be passed on to a return from a function, just like variables. For example I can create a function like below
var fn =function() {
console.log(‘This is function’);}
and I can pass the same function in another function which can be taken as a variable similarly I can return a
function from a function just like a variable. Sometimes the first-class functions are also called as higher-order functions.
Another characteristics in functional oriented programming is that, there are no loops but only recursions.
Programming languages which supports functional oriented programming are
- Haskell
- clojure
- scala
- Java
- C++
- python