2. Functional Programming
A programming paradigm that treats
computation as the evaluation of functions
and avoids state and mutable data.
3. Imperative Programming
A programming paradigm that treats
computation as the evaluation of functions
and avoids state and mutable data.
A programming paradigm that describes
computation in terms of statements that
change a program state.
4. The difference
A programming paradigm that treats
computation as the evaluation of functions
and avoids state and mutable data.
A programming paradigm that describes
computation in terms of statements that
change a program state.
Imperative functions can have side effects
that may change the value of program
state, so this approach looses...
5. Referential transparency
The same language expression can result
in different values at different times
depending on the state of the executing
program.
6. Pure Functions
● Always evaluates the same result value
given the same argument values
● Evaluation of the result does not cause
any side effect
7. Pure
● sin
● to_s
● Enumerable#select
● Enumerable#collect
● Array#uniq
● Hash#merge
9. Pure Functions is Good
● Can be cached/memoized
● Order of calculation does not matter
● Any evaluation strategy can be used
● Chain can be easily paralellized
18. Tail Call Optimization
Tail call is equivalent to iteration. So Tail
Call Optimization(TCO) is evaluating of
Tail Call as an iteration.
In Ruby TCO is turned off by default.
19. First Class Objects
● can be stored in values and data
structures
● can be passed as a parameter to an
expression
● can be returned as the result of a
expression
20. Higher-order Functions
Functions that can either take other
functions as arguments or return them as
results
21. Closure
A function or reference to a function
together with a referencing environment
28. Advantages of Functional
Programming
● Reliability
● Parallelizm
● Easy unit testing
● Easy debugging
29. Disadvantages of Functional
Programming
● Seems to be more difficult
● Typically less efficient
● Garbage collector needed
● Difficulties with IO methods and states