if you don’t buy FP, you won’t benefit from CS • if you buy FP, you can benefit even without using CS • from backend development experience • more relevant for parallel systems Setting expectations Thursday, February 21, 13
if you don’t buy FP, you won’t benefit from CS • if you buy FP, you can benefit even without using CS • from backend development experience • more relevant for parallel systems WORA Thursday, February 21, 13
env }; function wrapCookies(fn) { var f = function (env) { // do cookie-related things, // prepare for handler fn(env); // do more cookie-related stuff, // prepare for response } return f; } // Run! wrapCookies(handler)(env); Thursday, February 21, 13
(fn [request] ;; do cookie-related things, ;; prepare for handler (f env) ;; do more cookie-related stuff, ;; prepare for response ) Thursday, February 21, 13
verbs with nouns) • => no objects that could potentially store state • => no side effects • easy to test in isolation • easy to compose and reuse • easy to reproduce flows What does it give you? Thursday, February 21, 13
• they work well only when enclosed values don't change • mutable objects lead to unpredictable behavior (state sucks) • when you set something, second later you're not sure anymore if it's still set What does it give you? Thursday, February 21, 13
• decoupling data from functions doesn’t mean you can’t dispatch on type anymore • even if your data is decoupled from action, doesn’t guarantee it doesn’t change Thursday, February 21, 13
not change fact of coupling) • change internal state • implementer has to remember to clear errors on reload or state change • potentially destructive against the Model • code reuse would require implementing abstraction on higher level (base class or helper) Thursday, February 21, 13
object (immutability) • trivial to test • always yields same result given same input (can’t give same guarantee with shared state) • reusable/composable right away • always operating primitives, easy to understand Thursday, February 21, 13
take a framework that will test it all for me • can you rely on the presence of @order? • or on its consistency? • explicit vs implicit function calls • testing chained calls that rely on state is extremely hard • even implementing can be tricky Thursday, February 21, 13
isolation • no shared/mutable state • predictable results • obvious outcome • local bindings for shared state • refs/atoms for transactional mutable state • if STM doesn’t work well for your use-case (too many interleaving state) changes, use message passing Thursday, February 21, 13
sequence is • already calculated part • function to yield next part • controlling flow, avoiding fetching/calculation when you got enough data • avoid needless calculations • (potentially) infinite data structures • (potentially) smaller memory footprint • use chunks to win performance, when you need to prefetch more than just next step Thursday, February 21, 13
and isolate changes to data structure • when changes are isolated, compose them with mapper/ reducer/merger or any other mean Thursday, February 21, 13
efficient creation of “modified” versions • structural sharing • inherently thread & iteration-safe will not mutate in a middle • immutable modification yields new coll • composite • No need for defensive copy • Referential Transparency Thursday, February 21, 13