Functional programming
Functional programming is a programming paradigm in which we try to bind everything in a pure mathematical functional style. It is a declarative type of programming style. Its main focus is on “what to solve” in contrast to an imperative style where the main focus is “how to solve”
What is it?
When ever you search how to learn functional Programming and A result came that You should Forgot Everything You Know about Programming.
Is it True?
NO, IT’S NOT TRUE.
The thing you do is Refactor your Idea, That how to do Programming.
Without Functional Programming at certain level of Complexity You can go into mess because your uncomplex idea getting complex and complex day by day due to your programming Paradigm.
Definetely your system or application works but….
Its Really hard to explain or Fix bug.
Now, Whenever you are in mess and unable to fix bug of your application you start with a plain paper to redesign your System. To resign we should keep the working part of your application,throw the buggy part and Start programming to do Synk between them.
May be our Object Oriented Programming Design is little Messy because It make program so much complex that it’s Impossible to fix bug and then we think of Refactoring.
So, We start with a clean paper with Working parts of Our Apllication and start thinking about Functional Programming.
We don’t Need to forgot all the stuff about programming to start with Functional Programming. We have to be aware about basis because basic Never Gona change.
If I will say Computer Science is a Sub Division of Mathmatics You would’nt Get Suprise.
Isnt’it
The things we can Learn from mathmaticians that they can able to prove any logic in very vast manner without going into bug or error that they have Functions.
Mathmatical Function never change according to time or situation.
So, Here we are borrowing function from the mathmatician and started the Functional Programming paradigm.
Don’t change anything only look for Input and produce output.
Now on fresh paper with working part of application we Combine the all to a Function but proble is still same if something or some dataStructure are mutable then the problem arries because in mathamtics we have function having Immutable properties.
Make every data strctures Immutable.
Now How would we change the things if everything is Immutable.
Now we will ask for Copy of the datastrcture that have same things that we require. Means If we have an array we will ask for a copy of array a having middle element 5.
a = [1,2,3]
acopy = [1,5,3]
We have Pure functions.
Now we have a problem of COPIES? ISNT’IT?
Now the solution is Persistent Data Structure.
Ordinary data structures are ephemeral in the sense that making a change to the
structure destroys the old version, leaving only the new one.
But a persistent data structure or not ephemeral data structure is a data structure that always preserves the previous version of itself when it is modified.
What is it like?
Magic
No Magic
- You can Still Have redundant Code.
- You can still Write bad code using Functional Programming.
Does it Work?
yes, It works Seemlessly.