Here are my notes from Katie Miller's talk in RuPy 2013 about functional programming and higher-order functions.
- FP is awesome, and much more accessible than you might think. No need to be a genius.
- FP is a paradigm/style of programming. Associated to certain languages but can be done in any language.
- Treats computation as the evaluation of functions (in the math sense: Same output for same input. Only use input to calculate output).
- Referential transparency: Can replace the call to the function with its result without changing the behavior of the program. If it violates referential transparency, it has side effects.
- Harder to reason about, harder to spot bugs with side-effects. Also occasional missile launches may happen.
- Not everything needs to be functional, but isolate the code that isn't.
- A closure is a higher order function with its referencing environment. Can access the environment later on.
- FP has roots all the way in the 1930s - lambda calculus. Seen all over languages. Increasingly in newer ones: Clojure, F#, Elixir.
- Modularity is the motivation underpinning a lot of this. If you use a Unix terminal, you're aware of the concept.
- FP is not programming as a series of instructions, but functions with behavior, and composing pipelines out of them.
- "Why Functional Programming Matters" talks about special "FP glue" for sticking programs together: Lazy evaluation, higher-order functions (HOFs, not to be confused with The Hoff)
- Building Functions: Function composition, partial application, currying.
- FP's three musketeers: Map, filter, and fold/reduce.
- Demo using tributary.io
- Showing map vs. imperative loop. This is encapsulating a pattern, which is what HOFs are particularly good for.
- Showing filter vs. an imperative loop. Extracting the logic of visiting the data structure from the actual test
- Fold/reduce is actually a family of functions (also known as accumulate, aggregate, compress, inject). Can be left or right associative, strict or lazy.
- Foldl is a "for loop with an accumulator", foldR more like consing. Can be implemented with each other, as long as you're working with finite data.
- Map and filter can also be defined with fold.
- Anywhere you see a repeated pattern, it's worth thinking if you can extract the repetition out to a higher-order function.
- Showing a nice example of little functions, partially applied and composed to a pipeline using Underscore.js
Know Your AngularJS Inside Out
Build Your Own AngularJS helps you understand everything there is to understand about AngularJS (1.x). By creating your very own implementation of AngularJS piece by piece, you gain deep insight into what makes this framework tick. Say goodbye to fixing problems by trial and error and hello to reasoning your way through them