In a restricted sense ,functional programming means programming without mutable variables ,assignments ,loops and control structures .
In a wider sense, functional programming paradigm focuses on functions. When we focus on functions ,we think about what is to be done rather than how .
Example,
Suppose you have to calculate sum of the squares.
In an imperative style you would start thinking about initializing the sum variable as 0 , iterating over the list ,square each element by the number and adding the squares to the sum variable.
sumOfSquares(n){ int sum=0; for(int i=1;i<=n;i++){ int square= i*i; sum=sum+square; } }
Here there is iteration and mutable variables.
In functional thinking you would identify functions to be used .
take n.map (^2).sum
There are three words in this program: take,map and sum . Each of those words refers to a function. The “.” simply means: call the following function and the give it result of current function as the argument.
That’s it. The take function simply takes the first n integers starting from 1. map transforms this list by squaring each element of the list and produces another list sum takes a list and sums up to give one value.
Each function does only one job and we solve the problem in terms of functions and not in steps.
So ,functional programming is about applying function to data rather than bringing data to functions.
In a way , it's similar to using axe(function) to cut the wood(data) rather than bringing the wood to axe .
Natural ! Isn't it?