Functional Programming Old
We have :
- Inhererent Complexiity: Complexiitystemming from domain
- Accidental complexity: Complexity we create while trying to deal with inehrent complexity.
> Functional Programming removes Accidental Complexity.
Functional Programming properties:
Assignment less Programming:
Much like how we dont use goto while coding but its okay for compiler to use go under the hood.
goto is to strucutred programming assignment is to funtional programming (We try to avoid assignments)
We can make smart copies of objects instead of true copy or fully copy like trie data strcuture.
Functions as First class citizens.
We treat functions as we do to objects. A higher order function can :
- We can pass function to function.
- We can create function within a function.
- We can return function from function.
Pure Functions dont have side effects
Does not change anything
Does not depend on anything that changes: a. The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions of the program * We want lazy evaluation.
b. If our function depends on something which changes outside the function it cannot be lazy.
Functional Style vs Purely Functional Programming
Purely functional programming will not allow any mutability.(Haskell) Functional style Programming provides hgiher order functions (Java,C#)
Now lets consider method or Lambda Expression(anonymous Function) Only parameters list, body.
Inferred return type based on context, no name needed.
Passed to higher-order functions.
Familiar vs Simple
Complex (not simple) things seem easy to think about when they become familiar. Familiarity with something does not imply that thing is simple.Edit this page on GitHub