11 : From Math to Functional Programming
Published: 2020-04-23 01:36:35

Think I became JavaScript Geek, I just don’t want to think of learning React.js, so wanted to give up, but…. I am so curious about functional programming, can’t wait….to see on my program… I am not even motivated to make my project. I have no idea of UIUX… Whatever… Functional programming is the only thing I want to take care… Lol..

---- 
Functional programming is a programming paradigm in which we try to bind everything in pure mathematical functions 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”. It uses expressions instead of statements. An expression is evaluated to produce a value whereas a statement is executed to assign variables. Those functions have some special features discussed below.

---- 

Functional Programming is based on Lambda Calculus:
Lambda calculus is framework developed by Alonzo Church to study computations with functions. It can be called as the smallest programming language of the world. It gives the definition of what is computable. Anything that can be computed by lambda calculus is computable. It is equivalent to Turing machine in its ability to compute. It provides a theoretical framework for describing functions and their evaluation. It forms the basis of almost all current functional programming languages.

---- 
Fact: Alan Turing was a student of Alonzo Church who created Turing machine which laid the foundation of imperative programming style.
----

Programming Languages that support functional programming: Haskell, JavaScript, Scala, Erlang, Lisp, ML, Clojure, OCaml, Common Lisp, Racket.

---- 
Concepts of functional programming:
Pure functions
Recursion
Referential transparency
Functions are First-Class and can be Higher-Order
Variables are Immutable


----
Advantages and Disadvantages of Functional programming
Advantages:
Pure functions are easier to understand because they don’t change any states and depend only on the input given to them. Whatever output they produce is the return value they give. Their function signature gives all the information about them i.e. their return type and their arguments.
The ability of functional programming languages to treat functions as values and pass them to functions as parameters make the code more readable and easily understandable.

-----
Testing and debugging is easier. Since pure functions take only arguments and produce output, they don’t produce any changes don’t take input or produce some hidden output. They use immutable values, so it becomes easier to check some problems in programs written uses pure functions.
It is used to implement concurrency/parallelism because pure functions don’t change variables or any other data outside of it.
It adopts lazy evaluation which avoids repeated evaluation because the value is evaluated and stored only when it is needed.

---- 
Disadvantages:
Sometimes writing pure functions can reduce the readability of code.
Writing programs in recursive style instead of using loops can be bit intimidating.
Writing pure functions are easy but combining them with rest of application and I/O operations is the difficult task.
Immutable values and recursion can lead to decrease in performance.
Applications:
It is used in mathematical computations.
It is needed where concurrency or parallelism is required.