why javascript functional programming is so hard?

20
WHY JAVASCRIPT FUNCTIONAL PROGRAMMING IS SO HARD? Feb 2, 2016 Welcome to Fantasy Land!

Upload: reactima

Post on 21-Jan-2017

438 views

Category:

Internet


3 download

TRANSCRIPT

WHY JAVASCRIPT FUNCTIONAL PROGRAMMING

IS SO HARD?

Feb 2, 2016

Welcome to Fantasy Land!

Functional Programming Visualized

Core Functional ConceptsFirst Class Functions stored in variables, passed as arguments to functions, created within functions and returned from functions

Higher Order Functions can accept functions as arguments, and/or can return a function

Pure Functions is a function where the return value is only determined by its input values, without observable Side Effects

Referential Transparency for a given set of arguments, the same code should always output the same value, only by changing arguments can a output value be different

Immutability is an inability for variables to change their values once created. In other words, all things created stay constant

Core Functional ConceptsCurrying / Partial Application - ability of a function to return a new function until it receives all it's arguments. Calling a curried function with only some of its arguments is called partial application

Tail Call Optimization - ability to avoid allocating a new stack frame for a function call. The most common use is tail-recursion, where a recursive function uses constant stack space.

Pattern matching is a form of conditional branching which allows you to concisely match on data structure patterns and bind variables at the same time

Lazy Evaluation means that expressions are not evaluated when they are bound to variables, but their evaluation is deferred until their results are needed by other computations

Recommended ReadingMostly Adequate Guide to Functional Programming, https://drboolean.gitbooks.io/mostly-adequate-guide/content/

Tail call optimization in ECMAScript 6, http://www.2ality.com/2015/06/tail-call-optimization.html

Functional Pattern Matching in JavaScript, https://github.com/bramstein/funcy

Functional JavaScript Fundamentalshttp://www.slideshare.net/Ssrdjan/functional-javascript-37401024

Want more? Put previously mentioned terms in Twitter ;)))

SO WHY FUNCTIONAL PROGRAMMING

IS SO HARD?

WHY SO HARD?Luck of understanding modern JavaScript aka ES6

https://github.com/reactima/reactima-redux-ecosystem/blob/master/JS.md

WHY SO HARD?

Imperative Habits

Most of us spend our lives, in looping structures and if-then-else statements.

It’s hard to treat functions as variables and see chaining process

99% of PROGRAMMERS DO THIS

FUNCTIONAL MINDED CODE

WHY SO HARD?

MATH TERMS ARE ANNOYINGMost developers don’t bother to understand

underlying concepts

MONADMonad is defined computation as sequences of steps: a type with a monad structure defines what it means to chain operations, or nest functions of that type together.

This allows the programmer to build pipelines that process data in steps, in which each action is decorated with additional processing rules provided by the monadhttps://en.wikipedia.org/wiki/Monad_(functional_programming) Monads in JavaScript, https://curiosity-driven.org/monads-in-javascript Functors, Applicatives, And Monads In Pictures http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

CRAZY?

99% of developers would never bother understand the next slide

WELCOME TO FANTASY LAND!Spend some time with specification for interoperability of common algebraic structures in JavaScript

VISIT US!https://github.com/fantasyland/fantasy-land

DEATH CHART

Issue Open vs. Close Rate Over a Four Month Period IMPERATIVE HABITS CONTRIBUTE A LOT TO THIS

CHART!

NEXT?

I don’t understand concepts!I just like to do coding!SHOW ME THE CODE!

I don’t understand concepts!SHOW ME THE CODE!

READ RAMDA TESTS!https://github.com/ramda/ramda/tree/master/test

Thank you!

Ilya Sidorov @reactima Interested to talk?

Let’s have a skype call: ilya.sidorov

[email protected] https://www.linkedin.com/in/reactima

https://github.com/reactima/