From Parentheses To Perception How Your Code Becomes Anothers - - PowerPoint PPT Presentation

from parentheses to perception
SMART_READER_LITE
LIVE PREVIEW

From Parentheses To Perception How Your Code Becomes Anothers - - PowerPoint PPT Presentation

From Parentheses To Perception How Your Code Becomes Anothers Reality Jenna Zeigen Node+JS Interactive 2018 October 11, 2018 @zeigenvector jenna.is/at-node-js-interactive Senior Frontend Engineer at Slack Organizer of EmpireJS


slide-1
SLIDE 1

@zeigenvector jenna.is/at-node-js-interactive

From Parentheses To Perception

Jenna Zeigen Node+JS Interactive 2018 October 11, 2018

How Your Code Becomes Another’s Reality

slide-2
SLIDE 2

@zeigenvector jenna.is/at-node-js-interactive

Senior Frontend Engineer at Slack Organizer of EmpireJS Organizer of BrooklynJS

slide-3
SLIDE 3

@zeigenvector jenna.is/at-node-js-interactive

jenna.is/at-node-js-interactive @zeigenvector

slide-4
SLIDE 4

@zeigenvector jenna.is/at-node-js-interactive

<button type="button" class="Button send-button" > Send </button> .Button { font-size: 16px; background: #128853; color: #fff; border-radius: 5px; } const button = document.querySelector('.send-button'); button.addEventListener('click', onBtnClick);

Nom nom nom!

slide-5
SLIDE 5

@zeigenvector jenna.is/at-node-js-interactive

This is a button and I know I can click it and it’ll do something!

slide-6
SLIDE 6

@zeigenvector jenna.is/at-node-js-interactive

  • 1. Parsing
  • 2. Rendering
  • 3. Perceiving
  • 4. Comprehending
slide-7
SLIDE 7

@zeigenvector jenna.is/at-node-js-interactive

  • 1. Parsing
  • 2. Rendering
  • 3. Perceiving
  • 4. Comprehending
slide-8
SLIDE 8

@zeigenvector jenna.is/at-node-js-interactive

  • 1. Parsing
  • 2. Rendering
  • 3. Perceiving
  • 4. Comprehending
slide-9
SLIDE 9

@zeigenvector jenna.is/at-node-js-interactive

We made computers so we know all the answers. We do science on humans to get closer to the answers.

slide-10
SLIDE 10

@zeigenvector jenna.is/at-node-js-interactive

Parsing

How does the browser process HTML, CSS, and JavaScript?

I begin to parse, To split the text apart Break it down into sections Tokens into selectors

♪♪♪

The Notorious B.I.G. – Sky's The Limit

slide-11
SLIDE 11

@zeigenvector jenna.is/at-node-js-interactive

Parsing

Most programming languages have a vocabulary described using regular expressions and a syntax described by a context-free grammar.

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork https://en.wikipedia.org/wiki/Context-free_grammar MC Hammer - U Can't Touch This

Stop! Grammar time!

♪♪♪

slide-12
SLIDE 12

@zeigenvector jenna.is/at-node-js-interactive

Parsing

Parsers take a document and break it into a structure the browser can use.

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork Ashlee Simpson - Pieces of Me

It's as if you know me better Than I ever knew myself I love how you can tell All the pieces, pieces, pieces of me

♪♪♪

slide-13
SLIDE 13

@zeigenvector jenna.is/at-node-js-interactive

Parsing

Parsing can be separated into two parts— lexical and syntactic analysis— which are performed by a lexer and parser, respectively

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork Katy Perry - Part of Me

This is the parse of me That you’re never gonna ever Take away from me, no!

♪♪♪

slide-14
SLIDE 14

@zeigenvector jenna.is/at-node-js-interactive

Parsing

HTML isn’t a context-free language and therefore can’t be parsed by a regular parser

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork Shakira - Whenever, Wherever

Whatever, wherever I’m gonna make it render!

♪♪♪

slide-15
SLIDE 15

@zeigenvector jenna.is/at-node-js-interactive

Parsing

Instead, browsers write custom parsers for HTML

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork Meghan Trainor - All About That Bass

Yeah, my momma she told me Don't worry about your size She says I’m this big ‘cause sometimes humans just aren’t so bright!

♪♪♪

slide-16
SLIDE 16

@zeigenvector jenna.is/at-node-js-interactive

Parsing

CSS is a context-free language and therefore easier to parse.

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork Snoop Dogg & Wiz Khalifa ft. Bruno Mars - Young, Wild, & Free

This parser’s young and wild and context-free

♪♪♪

slide-17
SLIDE 17

@zeigenvector jenna.is/at-node-js-interactive

Parsing

Both HTML and CSS parsers end up building a tree representing the language it parsed, the DOM and CSSOM trees

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork The Foundations - Build Me Up Buttercup

So build me up, buttercup Don’t break my parse

♪♪♪

slide-18
SLIDE 18

@zeigenvector jenna.is/at-node-js-interactive

Parsing

https://www.html5rocks.com/en/tutorials/internals/howbrowserswork

document html head body div title h1 button "Slack!" "Send" body div h1 .Button

font-size: 12px font-size: 36px font-weight: bold font-size: 16px background: #128853; color: #fff; border-radius: 5px; font-size: 12px
slide-19
SLIDE 19

@zeigenvector jenna.is/at-node-js-interactive

Parsing

JavaScript is also context-free and can use a regular parser, but browsers complicate things in order to optimize

http://www.ecma-international.org/ecma-262/#sec-notational-conventions https://www.youtube.com/watch?v=Fg7niTmNNLg Daft Punk - Harder, Better, Faster, Stronger

Harder, better, faster parser!

♪♪♪

slide-20
SLIDE 20

@zeigenvector jenna.is/at-node-js-interactive

Parsing

V8 uses two parsers— eager and lazy— to eventually create an abstract syntax tree and scope structure

https://www.youtube.com/watch?v=Fg7niTmNNLg Flo Rida - Low

Scripty’s now an abstract syntax tree Thanks, smart parser (smart parser!)...

♪♪♪

slide-21
SLIDE 21

@zeigenvector jenna.is/at-node-js-interactive

Parsing

The AST and scope structures get turned into low-level code

The next step is the baseline compiler It made bytecode (it made bytecode!) Next thing you know Scripty got low-low-low Low-low-low-low-low

♪♪♪

https://www.youtube.com/watch?v=Fg7niTmNNLg Flo Rida - Low

slide-22
SLIDE 22

@zeigenvector jenna.is/at-node-js-interactive

Parsing

The low-level code then gets executed

https://www.youtube.com/watch?v=Fg7niTmNNLg R Kelly - Ignition

Interpreted by Ignition Your code's coming to fruition

♪♪♪

slide-23
SLIDE 23

@zeigenvector jenna.is/at-node-js-interactive

Parsing

The bytecode also gets fed to the optimizing compiler which spits out machine code

https://www.youtube.com/watch?v=p-iiEDtpy6I Enya - Only Time

Who can say where that byte goes Turbofan does, at runtime And who can say if your code flows Turbofan knows, just-in-time

♪♪♪

slide-24
SLIDE 24

@zeigenvector jenna.is/at-node-js-interactive

Rendering

How does the browser put pixels on the screen and move ‘em around?

Well, I'm gonna paint my picture Paint myself in blue and red and green and... a All of the beautiful pixels are very, very meaningful

♪♪♪

Counting Crows - Mr. Jones

slide-25
SLIDE 25

@zeigenvector jenna.is/at-node-js-interactive

Rendering

The DOM and CSSOM trees are combined to form the render tree

O render tree, O render tree How lovely are thy branches

♪♪♪

https://developers.google.com/web/fundamentals/ performance/critical-rendering-path/render-tree-construction https://en.wikipedia.org/wiki/O_Tannenbaum

slide-26
SLIDE 26

@zeigenvector jenna.is/at-node-js-interactive

Rendering

https://developers.google.com/web/fundamentals/ performance/critical-rendering-path/render-tree-construction

RenderView Scroll Block Block Block Block Block Text Text

+ =

document html head body div title h1 button "Slack!" "Send" body div h1 button

font-size: 12px font-size: 36px font-weight: bold font-size: 16px background: #128853; color: #fff; border-radius: 5px; font-size: 12px
slide-27
SLIDE 27

@zeigenvector jenna.is/at-node-js-interactive

Rendering

The browser traverses the render tree, calculating the location and size of all elements

https://developers.google.com/web/fundamentals/ performance/critical-rendering-path/render-tree-construction Taylor Swift - Shake it Off

And the render’s gonna rend, rend, rend?

♪♪♪

slide-28
SLIDE 28

@zeigenvector jenna.is/at-node-js-interactive

Rendering

The browser again traverses the render tree, creating bitmaps for each layer

https://www.youtube.com/watch?v=gqc88qWuiI4 Taylor Swift - Shake it Off

And the painter’s gonna paint, paint, paint

♪♪♪

slide-29
SLIDE 29

@zeigenvector jenna.is/at-node-js-interactive

Rendering

Bitmaps are sent to the GPU for compositing

https://www.youtube.com/watch?v=gqc88qWuiI4 https://www.html5rocks.com/en/tutorials/speed/layers/ Taylor Swift - Shake it Off

And the GPU’s gonna composite, composite, composite…

♪♪♪

slide-30
SLIDE 30

@zeigenvector jenna.is/at-node-js-interactive

Rendering

The browser repeats the process, maybe 60 times a second

https://www.html5rocks.com/en/tutorials/speed/layers/ Katy Perry - Last Friday Night (T.G.I.F.)

Do it allll agaaaain…

♪♪♪

slide-31
SLIDE 31

@zeigenvector jenna.is/at-node-js-interactive

Rendering

JavaScript runs on the browser’s main thread with everything else

https://www.youtube.com/watch?v=p-iiEDtpy6I Salt-N-Pepa - Shoop

Loop loop ba-doop loop ba-doop Loop ba-doop ba-doop Ba-doop loop ba-doop loop Ba-doop loop ba-doop, ba-doop, ba-doop

♪♪♪

slide-32
SLIDE 32

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

https://en.wikipedia.org/wiki/Visual_system James Blunt - You’re Beautiful

How does the brain paint pictures of the world and recognize what we see?

It’s beautiful It’s beautiful It’s beautiful, it's true This interface, it’s a crowded place But I know just what to do

♪♪♪

slide-33
SLIDE 33

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

Light goes into the eye via the cornea and lens

https://en.wikipedia.org/wiki/Visual_system Johnny Nash - I Can See Clearly Now

I can see clearly now The light is on

♪♪♪

slide-34
SLIDE 34

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

The retina turns the light into neural signals using rods and cones

https://en.wikipedia.org/wiki/Visual_system https://en.wikipedia.org/wiki/Flicker_fusion_threshold Kanye West - All of the Lights

Turn up the lights in here, baby You know what I need Want you to see everything Want you to see all of the lights

♪♪♪

slide-35
SLIDE 35

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

The neural signals get sent via the optic nerve to the brain

https://en.wikipedia.org/wiki/Visual_system Thursday - Signals Over the Air

The signals that we send Over the nerves Over the nerves Over the nerves Over the nerves.

♪♪♪

slide-36
SLIDE 36

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

Signals from both eyes reach the

  • ptic chiasm, are combined,

split by visual field, and sent to the opposite side of the brain

https://en.wikipedia.org/wiki/Visual_system Zedd, Maren Morris, Grey - The Middle

Why don’t you just meet me in the middle, In the middle

♪♪♪

slide-37
SLIDE 37

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

https://commons.wikimedia.org/wiki/File:1204_Optic_Nerve_vs_Optic_Tract.jpg

It me!

slide-38
SLIDE 38

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

Most signals get sent to the lateral geniculate nuclei, which collates information from different eyes

Blake, R., & Sekuler, R. (2006) Joni Mitchell - Both Sides Now

I've looked at life from both sides now From left and right and still somehow

♪♪♪

slide-39
SLIDE 39

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

Signals then get sent to the primary visual cortex

Blake, R., & Sekuler, R. (2006) Lady Gaga - Edge of Glory

I have an edge of glory

♪♪♪

slide-40
SLIDE 40

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

Signals gets sent to higher visual processing centers that help us actually perceive what we are seeing

Blake, R., & Sekuler, R. (2006) Passion Pit - Little Secrets

It's the way I see Everything I need … Higher and higher and higher Higher and higher and higher

♪♪♪

slide-41
SLIDE 41

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

We start to figure out what is background and what are different objects

Blake, R., & Sekuler, R. (2006) Kellogg (2007) Beyoncé - XO

In the darkest night I’ll I’ll search through the crowd Your shape is all that I see I’ll give you everything

♪♪♪

slide-42
SLIDE 42

@zeigenvector jenna.is/at-node-js-interactive

Perceiving

We translate data about different regions into data about different forms, such as size and shape

Blake, R., & Sekuler, R. (2006) Ed Sheehan - Shape of You

(no, not <form>s, silly) Every day discovering something brand new I can discern the shape of you

♪♪♪

slide-43
SLIDE 43

@zeigenvector jenna.is/at-node-js-interactive

Then, we start to recognize and identify objects.

Blake, R., & Sekuler, R. (2006) KT Tunstall - Suddenly I See

Perceiving

Suddenly I see (suddenly I see) What that’s supposed to be Suddenly I see (suddenly I see) Why the hell it means so much to me

♪♪♪

slide-44
SLIDE 44

@zeigenvector jenna.is/at-node-js-interactive

Our minds take choppy, discrete inputs and create a seamless experience that we perceive as continuous

Blake, R., & Sekuler, R. (2006) Smooth - Santana ft. Rob Thomas

Perceiving

You got the kind of vision That can be so ~smooth~, yeah Might be choppy, make it real Or else forget about it

♪♪♪

slide-45
SLIDE 45

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

How do we understand written language?

Do you read me?

slide-46
SLIDE 46

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

To understand written language, we first have to recognize pixels on the screen as words

word.

slide-47
SLIDE 47

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

We process words as holistic units, not as separate letters, and we recognize words faster than non-words.

Blake, R., & Sekuler, R. (2006) Jack Johnson - Better Together

It's not always easy and Sometimes words can be deceiving I'll tell you one thing, Letters are better when they’re together

♪♪♪

slide-48
SLIDE 48

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

We are also able to understand wordswhentheyaresmushedtogether better than if theyh aves paces inarb itraryp la ces

Blake, R., & Sekuler, R. (2006) Arctic Monkeys - Do I Wanna Know?

I wanna know Does this meaning flow both ways

♪♪♪

slide-49
SLIDE 49

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

We are also able to understand words when they are smushed together better than if they have spaces in arbitrary places

Blake, R., & Sekuler, R. (2006) Arctic Monkeys - Do I Wanna Know?

I wanna know Does this meaning flow both ways

♪♪♪

slide-50
SLIDE 50

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Our minds match the word we see to the representations of words we have stored in our minds

Lupker (2005) Justin Bieber - What Do You Mean?

First you're up and you’re down And then between Oh I really want to know What do you mean? Ooh

♪♪♪

slide-51
SLIDE 51

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Once we access a word, we have access to its meaning and its syntactic and thematic roles

Role up! Role up for the magic mystery tour

♪♪♪

The Beatles - Magical Mystery Tour

slide-52
SLIDE 52

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

We then parse the sentence, construct a representation of its meaning

Yeah, it's just a phrase It will be over soon Yeah, it's just a phrase Yeah, it's just a... Phrase

♪♪♪

Incubus - Just a Phase

slide-53
SLIDE 53

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Garden Path Theory: We construct the simplest parse first, and then see if it makes sense semantically based on context

https://en.wikipedia.org/wiki/Sentence_processing Aaliyah - Try Again

If at first you don't succeed (First you don't succeed), Dust yourself off, and try again You can dust it off and try again Try again

♪♪♪

slide-54
SLIDE 54

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

“The horse raced past the barn fell”

https://en.wikipedia.org/wiki/Sentence_processing

slide-55
SLIDE 55

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

“The horse (that) raced past the barn fell”

https://en.wikipedia.org/wiki/Sentence_processing

slide-56
SLIDE 56

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Constraint-based Theories: we interpret sentences based on probabilistic constraints

https://en.wikipedia.org/wiki/Sentence_processing Chvrches - Keep You on My Side

We feel the same With these constraints We feel the same Within our brains

♪♪♪

slide-57
SLIDE 57

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Human language contains a ton of ambiguity, both semantic and syntactic

One way or another, I'm gonna find ya' I'm gonna get ya', get ya’, Get ya', get ya’

♪♪♪

Blondie - One Way or Another

slide-58
SLIDE 58

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

Humans are very forgiving of syntax errors

And here's to you ‘Cause forgiveness is a nice thing to do

♪♪♪

Taylor Swift - This is Why We Can’t Have Nice Things

slide-59
SLIDE 59

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

BLUE PURPLE RED GREEN PURPLE GREEN

slide-60
SLIDE 60

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

slide-61
SLIDE 61

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

BLUE PURPLE RED GREEN PURPLE GREEN

slide-62
SLIDE 62

@zeigenvector jenna.is/at-node-js-interactive

Comprehending

BLUE PURPLE RED GREEN PURPLE GREEN

slide-63
SLIDE 63

@zeigenvector jenna.is/at-node-js-interactive

  • 1. Parsing
  • 2. Rendering
  • 3. Perceiving
  • 4. Comprehending
slide-64
SLIDE 64

@zeigenvector jenna.is/at-node-js-interactive

Books

  • Blake, R., & Sekuler, R. & (2006). Perception (5th ed.). Boston: McGraw-Hill.
  • Harley, T. A. (2008). Psychology of Language: From Data to Theory (3rd ed.). New

York: Psychology Press.

  • Kellogg, R. T. (2007). Fundamentals of cognitive psychology. Thousand Oaks, CA:

SAGE.

Websites

  • https://www.html5rocks.com/en/tutorials/internals/howbrowserswork
  • https://www.html5rocks.com/en/tutorials/speed/layers/
  • https://developers.google.com/web/fundamentals/performance/critical-rendering-

path/render-tree-construction

  • Marja Hölttä: Parsing JavaScript - better lazy than eager? (Video)
  • Franziska Hinkelmann: JavaScript engines - how do they even? (Video)
  • Chelsea Derrick: True Grit: Debugging CSS & Render Performance (Video)
  • www.ecma-international.org/ecma-262/
  • https://en.wikipedia.org/wiki/Visual_system
  • https://en.wikipedia.org/wiki/Lateral_geniculate_nucleus
  • https://en.wikipedia.org/wiki/Language_processing_in_the_brain
  • https://en.wikipedia.org/wiki/Sentence_processing
  • Visual Word Recognition: Theories and Findings

Resources

slide-65
SLIDE 65

@zeigenvector jenna.is/at-node-js-interactive

Tracklist

The Notorious B.I.G. – Sky's The Limit MC Hammer - U Can't Touch This Ashlee Simpson - Pieces of Me Katy Perry - Part of Me Shakira - Whenever, Wherever Meghan Trainor - All About That Bass Snoop Dogg & Wiz Khalifa ft. Bruno Mars - Young, Wild, & Free The Foundations - Build Me Up Buttercup Daft Punk - Harder, Better, Faster, Stronger Flo Rida - Low R Kelly - Ignition Enya - Only Time Counting Crows - Mr. Jones Traditional - O Tannenbaum Taylor Swift - Shake it Off Katy Perry - Last Friday Night (T.G.I.F.) Salt-N-Pepa - Shoot James Blunt - You’re Beautiful Johnny Nash - I Can See Clearly Now

slide-66
SLIDE 66

@zeigenvector jenna.is/at-node-js-interactive

Tracklist

Kanye West - All of the Lights Thursday - Signals Over the Air Zedd, Maren Morris, Grey - The Middle Joni Mitchell - Both Sides Now Lady Gaga - Edge of Glory Passion Pit - Little Secrets Beyoncé - XO Ed Sheehan - Shape of You KT Tunstall - Suddenly I See Smooth - Santana ft. Rob Thomas Jack Johnson - Better Together Arctic Monkeys - Do I Wanna Know? Justin Bieber - What Do You Mean? The Beatles - Magical Mystery Tour Incubus - Just a Phase Aaliyah - Try Again Chvrches - Keep You on My Side Blondie - One Way or Another Taylor Swift - This is Why We Can’t Have Nice Things

slide-67
SLIDE 67

@zeigenvector jenna.is/at-node-js-interactive

Thanks!

jenna.is/at-node-js-interactive @zeigenvector