4. Object-Oriented Programming
Everything is an object
◦ State
◦ Behavior
You can consider objects as (badly
designed) state machines with a wide
space of states and transitions
6. Functional Programming
◦ Write expressive code.
◦ Write less code.
◦ Write performant code.
◦ Write code that we can easily
reason about.
The main goals are to reduce the input
and state space and ease reasoning.
8. “
If you say “a” is 5, you can’t say it’s
something else later because you just
said it was 5. What are you, some kind of
liar?
Miran Lipovaca - http://learnyouahaskell.com/
10. Values
Immutable
◦ You assign a value and can’t
reassign another one.
Data structure are immutable too. To
update them, you return a new
instance with the updated state.
15. ◦ Immutability eliminates state transition
▫ Passing values and data structure
reference is safe
For lists: Functional languages reuse data and will
not duplicate values.
Immutability
21. ◦ Take an argument and produce a result
◦ Pure functions do not have side-effects
▫ Change external state
▫ Modify a value
▫ Throw an exception
▫ Read from sdtin
▫ Write to disk
Functions
22. “
Functional programming is a restriction
on how we write programs, but not on
what we express.
Paul Chiusano and Rúnar Bjarnason - Functional Programming in Scala
23. ◦ Change external state
▫ Just don’t do it
◦ Modify a value
▫ Remember: immutable
◦ Throwing exception
▫ Return them as sentinel values
▫ Return an [Option] value
▫ Return an [Either] value
◦ I/O
▫ Most functional languages have the IO
monad1
Alternative to side-effects
1 http://en.wikipedia.org/wiki/Monad_%28functional_programming%29#The_I.2FO_monad
35. Useful combinators/High-order functions
map: Applies a function to each element of a list.
flatMap: Applies a function to a collection and
flattens the result by one level.
fold: Combines elements of a collection by
applying a given function recursively.
filter: Returns only the element that passes a
truth test.
36. Resources
◦ Félix-Étienne Trépanier - Confoo slides:
http://www.slideshare.net/felixtrepanier/intro-to-
functional-programming-confoo
◦ Martin Odersky - Functional Programming Principles in
Scala: https://www.coursera.org/course/progfun
◦ Miran Lipocava - Learn you a Haskell for Great Good !:
http://learnyouahaskell.com/
◦ JavaScript allongé:
https://leanpub.com/javascriptallongesix
◦ Paul Chiusano and Runr Bjarnason - Functional
Programming in Scala:
http://www.manning.com/bjarnason/
38. CREDITS
Special thanks to all the people who made and
released these awesome resources for free:
◦ Presentation template by SlidesCarnival
◦ Photographs by Unsplash
Code screenshots:
http://www.slideshare.net/felixtrepanier/intro-to-
functional-programming-confoo