# Functional Programming
## for Functioning Developers
Rob Bollons | [@robbollons](https://twitter.com/robbollons) | [thenorthcode.net](http://thenorthcode.net)
Note:
* About me:
* Started out as a Classic ASP VB programmer (Dont even know what paradigm)
* Learned JavaScript and worte AJAX applications using subroutines
* Suffered agony learning ASP.NET
* Moved to OOP C# with ASP.NET
* Got fed up of Classical Inheritance and moved to Prototypical Inheritance in JavaScript
* Got fed up of inheritance all together and discovered the joys of hybrid FP
* Opposite of functional programmer, imperative programmer
* Caveat - I am not an expert on functional programming
* Hope to cover the basics of funcitonal programming and get people interested in giving it a go
* Take away the stigma around the mathematical complexity
## What is Functional Programming?
Wikipedia: *"In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data."*
Note:
* FP expressed in expressions and mathematical functions.
* Typically based on lambda calculus but this is not required - intuition
* Combine in various ways to transform input and output
* Imperative express programs as subroutines and direct instructions
* Imperative is popular because machine code is imparative and so it is optimised
## Key Concepts
## Key Concepts:
### Pure Functions & Referential Transparency
Note:
* Pure functions: functions that have 0 side effects
* referential transparency: can replace the function call with the resulting value
* means code is much easier to test, more predicatable and cleaner
* functions that are referentially transparent can make use of memoization
* memoization is an optimization mechanism for caching the result of referentially transparent functions
## Key Concepts:
### Function Composition
Note:
* function composition is the true lego of programming
* glue functions together in different ways to preduce bigger functions
* relies on partial application and currying in order to work well
* ramda and lodash/fp have auto-curried functions in JavaScript
## Key Concepts:
### First Class & Higher Order Functions
Note:
* First class functions are a fundamental feature for FP
* Functions can be passed around and utilised like variables
* Higher order functions are functions that operate on other functions
* Higher order functions allow things such as partial application and currying
* partial application is the process of fixing particular values of a function and returning a new function with smaller arity
* currying is applying each argument in a function one at a time.
## Key Concepts:
### Recursion
![Recursion](../images/fp-fat.jpg)
Note:
* Typical iteration in FP is done using recursive functions
* A function calls it'self untill a base conditon is reached
* Allows for greater composition and resuse
* Languages that utilise a stack based approach like JavaScript
## Why Functional Programming?
![Aliens](../images/fp-aliens.jpg)
Note:
* OOP
* clean maintainable code in OOP is hard
* OOP always requires knowledge of the domain in order to maintain the code, bad for me with terminal forgetfullness
*