Top Banner
The Ecosystem: Making Sense of the Madness JS
35

JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Jun 29, 2018

Download

Documents

nguyentuyen
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

The Ecosystem:Making Sense of the Madness

JS

Page 2: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

www.popart.com

Page 3: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Ethan BrownDirector of Engineering

@[email protected]

UNDERGRAD

VCUMBA

PSUBOOKSLOCATION

PDX

Page 4: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

PLEASEFOLLOW

ALONG

https://jseco.zepln.com

Page 5: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

I mean, OOP was good back in the days, and it still has its uses today, but now everyone is realising modifying states is equivalent to kicking babies, so now everyone is moving to immutable objects and functional programming. Haskell guys had been calling it for years, -and don’t get me started with the Elm guys

https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f

Page 6: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 7: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

KNOWTHE

BIGPICTURE

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 8: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Elm

Page 9: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Elm

Page 10: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

ReactNative

NativeScript

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

Elm

Page 11: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

Elm

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Page 12: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Elm

Page 13: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Elm

Page 14: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

JS

webpack

Babel

Express

Node

IoT

TypeScriptClojureScript

WebAssembly

Angular

React

Vue

ReactNative

NativeScript

Elm

Page 15: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

KNOW

JS

(i mean really know it)

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 16: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

What are the three ways that arrow functions (=>) are different from functions declared with the function keyword?

Q1

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 17: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Array Spread / Rest Parameters

const newNames = [

...names.slice(0, 7),

"Summer",

...names.slice(7)

]

const maxAge = Math.max(...ages)

function strPad(prefix, suffix, ...strings) {

return strings.map(s => prefix + s + suffix)

}

Q2

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 18: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Object Spread

const b = {

...a,

x: "override",

}

Q3const c = {

x: "default",

...a,

}

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 19: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Destructuring

const { foo, bar, baz } = obj

const { target: { value } } = evt

const [ a, b, ...rest ] = arr

Q4

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 20: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Computed Property Names / Property Shorthand

const name = "Daenerys"

const chars = {

[name]: { name, role: "Ultimate Bada**" },

}

Q5

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 21: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Promises

return Promise.resolve()

.then(() => new Promise((resolve, reject) =>

readFile('file.txt', (err, data) => err ?

reject(err) : resolve(data))

))

.catch(err => console.error(err))

Q6

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 22: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

String Templates

`Hello, ${name}, you were born

in ${new Date.getFullYear() - age}!`

Q7

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 23: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

async / await

async function foo() {

const stuff = await fetch('/stuff').then(res => res.json())

const [things, facts] = Promise.all([

fetch(`/things?subject=${stuff.topic}`),

fetch(`/facts?subject=${stuff.topic}`),

])

console.log(things, facts)

} Q8

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 24: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Class Fields

class Thing {

foo = 33

static baz = 15

bloop() { return 'bloop' }

bloz = () => 'bloz'

}

Q9

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 25: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

for...of

for(let x of nums) {

console.log(x)

}

for(let x in nums) {

console.log(x)

}

What's the difference?Q10

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 26: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

export / import

export default Foo

export { Foo }

export { default as Foo } from './Foo'

export { default as Bar } from './Bar'

import Foo from './Foo'

import { Foo } from './Foo'

import { Foo, Bar } from './dir'

Q11

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 27: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

Don't Worry About

● Generators (primary use case replaced by async/await)

● Symbols

● OOP

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 28: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

KNOWYOUR

PARADIGMS

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 29: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

FUNCTIONAL PROGRAMMING

● No more side-effects!

● Better composability

● Better testabilityλThe JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 30: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

ONE-WAY DATA BINDING● Application state easier to manage

● Encourages "whole-application thinking"

● Time-travel debugging

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 31: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

IMMUTABILITY

● Natural fit for functional programming

● Identity comparison is fast and cheap in JavaScript

● Natural safety net encourages experimentation

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 32: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

CHOOSEYOUR

STACK

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 33: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

SIMPLE COMPLEX

FLEXIBLE

RIGID

Ember

Junior Developers

React + "Everything"

Thank you Ryan Stevens of Lending Club! https://youtu.be/CIVhvhdISRI

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 34: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

SIMPLE COMPLEX

FLEXIBLE

RIGID

Ember

Senior Developers

React + "Everything"

Thank you Ryan Stevens of Lending Club! https://youtu.be/CIVhvhdISRI

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/

Page 35: JavaScript Making Sense of the Madness - schd.wsschd.ws/hosted_files/nina17/b8/JavaScript- Making Sense of the... · FUNCTIONAL PROGRAMMING No more side-effects! ... Identity comparison

THANK YOU

The JS Ecosystem: Making Sense of the Madness - @EthanRBrown - http://jseco.zepln.com/