Slide 1

Slide 1 text

A Book Nerd’s Guide to JavaScript @angustweets

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

Practical, Useful, Mind Numbingly Boring Nonsensical Work of Genius

Slide 4

Slide 4 text

What can Literature teach us about Programming?

Slide 5

Slide 5 text

Great literature is the creation of open minds As programmers our focus can be very narrow

Slide 6

Slide 6 text

We’re encouraged to follow only one style…

Slide 7

Slide 7 text

Actual excerpts from: Google Style Guide AirBnb Style Guide JavaScript Garden

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

We’re left with only one way to get from A to B :(

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Literature is about embracing the entire language

Slide 14

Slide 14 text

When programmers embrace the entire language we get choices…

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

"There are indeed many ways to do the same thing in JS. That's one of the beauties of the language" - Peter van der Zee (@kuvos)

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

(at least until the JavaScript Police get here)

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Perhaps most importantly…

Slide 24

Slide 24 text

…Open Minds keep JavaScript fun.

Slide 25

Slide 25 text

This one just follows The Good Parts These two learn by experiment

Slide 26

Slide 26 text

As programmers we’re not encouraged to experiment

Slide 27

Slide 27 text

Yet experiment is what keeps JavaScript alive

Slide 28

Slide 28 text

“You need a lot of bad code to write good code” - Substack (dotJS 2014)

Slide 29

Slide 29 text

‣ if(!!x) ‣ fn && fn() ‣ immediately invoked functions ‣ module pattern ‣ promises

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

I decided to take experiment to the next level…

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Wait What?

Slide 34

Slide 34 text

Twenty Five Authors solving Five JavaScript Problems

Slide 35

Slide 35 text

Hemingway developed the Iceberg Theory

Slide 36

Slide 36 text

Here is Hemingway’s Iceberg Theory applied to JavaScript…

Slide 37

Slide 37 text

(weird shit) (Deceptively Familiar Syntax) (weird shit) JavaScript

Slide 38

Slide 38 text

(weird shit) JAVA!! (Deceptively Familiar Syntax) (weird shit) JavaScript

Slide 39

Slide 39 text

(weird shit) JAVA!! But Easier!! (Deceptively Familiar Syntax) (weird shit) JavaScript

Slide 40

Slide 40 text

(weird shit) JAVA!! But Easier!! (Deceptively Familiar Syntax) (weird shit) WTF? JavaScript

Slide 41

Slide 41 text

Generate Prime Numbers

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

// A succession of creatures mount the stairs;! // each creature's stride exceeds that of its predecessor! var monstersAscendingAStaircase = function(numberOfSteps) {! var stairs = []; stepsUntrodden = [];! var largestGait = Math.sqrt(numberOfSteps);! for (var i = 2; i <= largestGait; i++) {! if (!stairs[i]) {! for (var j = i * i; j <= numberOfSteps; j += i) {! stairs[j] = 'stomp';! }! }! }! ! // Long-limbed monsters won't tread on prime numbered stairs.! for (var i = 2; i <= numberOfSteps; i++) {! if(!stairs[i]) {! stepsUntrodden.push(i);! }! }! ! // Here, then, is our answer.! return stepsUntrodden;! };!

Slide 44

Slide 44 text

1 2 3 4 5 6 7 8 9 10 11 12 13 14 2 3 Borges vs. Prime Numbers

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

function downTheRabbitHole(growThisBig) {! var theFullDeck = Array(growThisBig);! var theHatter = Function('return this/4').call(2*2);! var theMarchHare = Boolean("The frumious Bandersnatch!");! ! var theVerdict = "the white rabbit".split(/the march hare/).slice(theHatter);! ! //into the pool of tears...! eval(theFullDeck.join("if (!theFullDeck[++theHatter]) {\! theMarchHare = 1;\! theVerdict.push(theHatter);\! " + theFullDeck.join("theFullDeck[++theMarchHare * theHatter]=true;") + "}")! );! ! return theVerdict;! }!

Slide 47

Slide 47 text

function downTheRabbitHole(growThisBig) {! var theFullDeck = Array(growThisBig);! var theHatter = Function('return this/4').call(2*2);! var theMarchHare = Boolean("The frumious Bandersnatch!");! ! var theVerdict = "the white rabbit".split(/the march hare/).slice(theHatter);! ! //into the pool of tears...! eval(theFullDeck.join("if (!theFullDeck[++theHatter]) {\! theMarchHare = 1;\! theVerdict.push(theHatter);\! " + theFullDeck.join("theFullDeck[++theMarchHare * theHatter]=true;") + "}")! );! ! return theVerdict;! }!

Slide 48

Slide 48 text

function downTheRabbitHole(growThisBig) {! var theFullDeck = Array(growThisBig);! var theHatter = Function('return this/4').call(2*2);! var theMarchHare = Boolean("The frumious Bandersnatch!");! ! var theVerdict = "the white rabbit".split(/the march hare/).slice(theHatter);! ! //into the pool of tears...! eval(theFullDeck.join("if (!theFullDeck[++theHatter]) {\! theMarchHare = 1;\! theVerdict.push(theHatter);\! " + theFullDeck.join("theFullDeck[++theMarchHare * theHatter]=true;") + "}")! );! ! return theVerdict;! }!

Slide 49

Slide 49 text

! new Array(5).join('A' + new Array(5).join('a'));! ! >! !

Slide 50

Slide 50 text

new Array(5).join("A" + new Array(5).join('a'));! ! > "AaaaaAaaaaAaaaaAaaaa"!

Slide 51

Slide 51 text

function downTheRabbitHole(growThisBig) {! var theFullDeck = Array(growThisBig);! var theHatter = Function('return this/4').call(2*2);! var theMarchHare = Boolean("The frumious Bandersnatch!");! ! var theVerdict = "the white rabbit".split(/the march hare/).slice(theHatter);! ! //into the pool of tears...! eval(theFullDeck.join("if (!theFullDeck[++theHatter]) {\! theMarchHare = 1;\! theVerdict.push(theHatter);\! " + theFullDeck.join("theFullDeck[++theMarchHare * theHatter]=true;") + "}")! );! ! return theVerdict;! }!

Slide 52

Slide 52 text

eval(“if(!theFullDeck[++theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}if(!theFullDeck[+ +theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}if(!theFullDeck[+ +theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}if(!theFullDeck[+ +theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}if(!theFullDeck[+ +theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}if(!theFullDeck[+ +theHatter]){theMarchHare=1;theVerdict.push(theHatter);theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;theFullDeck[+ +theMarchHare*theHatter]=true;theFullDeck[++theMarchHare*theHatter]=true;}”);!

Slide 53

Slide 53 text

eval(“if (!theFullDeck[++theHatter]) {! theMarchHare = 1;! theVerdict.push(theHatter);! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! }! if (!theFullDeck[++theHatter]) {! theMarchHare = 1;! theVerdict.push(theHatter);! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! theFullDeck[++theMarchHare * theHatter] = true;! }! if (!theFullDeck[++theHatter]) {! theMarchHare = 1;!

Slide 54

Slide 54 text

Alice in Prime Numberland

Slide 55

Slide 55 text

Alice in Prime Numberland

Slide 56

Slide 56 text

Alice in Prime Numberland

Slide 57

Slide 57 text

Alice in Prime Numberland

Slide 58

Slide 58 text

Alice in Prime Numberland

Slide 59

Slide 59 text

Alice in Prime Numberland

Slide 60

Slide 60 text

Alice in Prime Numberland

Slide 61

Slide 61 text

Alice in Prime Numberland

Slide 62

Slide 62 text

Alice in Prime Numberland

Slide 63

Slide 63 text

Alice in Prime Numberland

Slide 64

Slide 64 text

Alice in Prime Numberland

Slide 65

Slide 65 text

So what did we learn?

Slide 66

Slide 66 text

Playing is Learning

Slide 67

Slide 67 text

Self-taught programmers are often the best programmers because they get to make mistakes

Slide 68

Slide 68 text

Experiment, Play, Have Fun and Keep an Open Mind.

Slide 69

Slide 69 text

Fin, merci! @angustweets anguscroll.com/hemingway

Slide 70

Slide 70 text

Books: http://pixgood.com/classic-book-spines.html/ Montparnasse Tower: http://allparisguides.com Eiffel Tower: Yellow Monster: http://content.mycutegraphics.com/ Green Monster: http://wondersofdisney2.yolasite.com/ White Rabbit: http://www.clker.com/ Mad Hatter, March Hare: http://wondersofdisney2.yolasite.com/ Cow, tree, office buildings: clipartpanda.com/ Grass: imgarcade.com/ Lion cubs: https://www.flickr.com/photos/mbiddulph/6947067048/ Cheetah cubs: http://www.bhmpics.com/view-cheetah_cubs_playing-1920x1080.html/ ! Image credits