Slide 1

Slide 1 text

Godfrey Chan @chancancode

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

eh? Accent

Slide 5

Slide 5 text

eh? Accent Healthcare

Slide 6

Slide 6 text

eh? Accent Healthcare Texas

Slide 7

Slide 7 text

eh? Accent Healthcare $ Taxes

Slide 8

Slide 8 text

eh? Accent gem install canada

Slide 9

Slide 9 text

eh? Accent >> require 'canada' => true >> [].empty_eh? => true >> [1,2,3].empty_eh? => false

Slide 10

Slide 10 text

eh? Accent Healthcare $ Taxes

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Impress your peers with powerful thought leadership skills! Thought Leadership A Reference for the Rest of Us!® FREE eTips at dummies.com® All the best kept secrets of seasoned thought leaders in one book ®

Slide 14

Slide 14 text

Programmer to Thought Leader™ Professional Thought Leadership Aaron Patterson , Gorby Puff, David Heinemeier Hansson g g n n o o r r w w ™

Slide 15

Slide 15 text

Chapter 1 Create Controversies “TDD is dead.” David Heinemeier Hansson

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Thought Leadership Is Dead

Slide 18

Slide 18 text

http://rails-weekly.goodbits.io

Slide 19

Slide 19 text

Dropping Down To The Metal™ ™

Slide 20

Slide 20 text

JavaScript

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Syntax

Slide 23

Slide 23 text

JIT Hints

Slide 24

Slide 24 text

JIT Hints

Slide 25

Slide 25 text

JIT Hints

Slide 26

Slide 26 text

JIT Hints

Slide 27

Slide 27 text

function square(x) { return (x * x); } function diag(a, b) { return Math.sqrt( square(a) + square(b) ); } JIT Hints

Slide 28

Slide 28 text

function square(x) { return (x * x); } function diag(a, b) { return Math.sqrt( square(a) + square(b) ); } JIT Hints

Slide 29

Slide 29 text

function square(x) { x = +x; return +(x * x); } function diag(a, b) { a = +a; b = +b; return +Math.sqrt(square(a) + square(b)); } JIT Hints

Slide 30

Slide 30 text

function square(x) { x = +x; return +(x * x); } function diag(a, b) { a = +a; b = +b; return +Math.sqrt(square(a) + square(b)); } x = +x; + a = +a; b = +b; + JIT Hints

Slide 31

Slide 31 text

function square(x) { x = +x; return +(x * x); } function diag(a, b) { a = +a; b = +b; return +Math.sqrt(square(a) + square(b)); } x = +x; + a = +a; b = +b; + Much Speed 5% Faster WOW Seems le JIT JIT Hints

Slide 32

Slide 32 text

660M 673M 685M 698M 710M Ops/sec Such Chart w/o JIT Hints w/ JIT Hints JIT Hints

Slide 33

Slide 33 text

660M 673M 685M 698M 710M Ops/sec Such Chart w/o JIT Hints w/ JIT Hints JIT Hints

Slide 34

Slide 34 text

0M 178M 355M 533M 710M Ops/sec Such Chart w/o JIT Hints w/ JIT Hints JIT Hints

Slide 35

Slide 35 text

+

Slide 36

Slide 36 text

JS Syntax +

Slide 37

Slide 37 text

JS Syntax Speed +

Slide 38

Slide 38 text

JS Syntax Speed Ruby VM +

Slide 39

Slide 39 text

JS Syntax Speed Ruby VM Magic +

Slide 40

Slide 40 text

JS Syntax Speed Ruby VM Magic + Awesome

Slide 41

Slide 41 text

JS Syntax Speed Ruby VM Magic + Awesome Amaze

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

gem install javascript

Slide 44

Slide 44 text

Java

Slide 45

Slide 45 text

Running Java with Ruby public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb

Slide 46

Slide 46 text

Running Java with Ruby public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb % ruby java.rb ??? Terminal

Slide 47

Slide 47 text

Running Java with Ruby public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb % ruby java.rb ??? Terminal A. It works™

Slide 48

Slide 48 text

Running Java with Ruby public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb % ruby java.rb ??? Terminal A. It works™ B. Syntax Error

Slide 49

Slide 49 text

Running Java with Ruby public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb % ruby java.rb ??? Terminal A. It works™ B. Syntax Error C. Runtime Error

Slide 50

Slide 50 text

Running Java with Ruby A. It works™ B. Syntax Error C. Runtime Error public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World"); } } java.rb % ruby java.rb java.rb:2: syntax error, unexpected tIDENTIFIER, expecting ')' public static void main(String[] args) { ^ java.rb:4: syntax error, unexpected '}', expecting '(' Terminal

Slide 51

Slide 51 text

How Ruby works Your Code Output Ruby Interpreter ???

Slide 52

Slide 52 text

How Ruby works Your Code Output Ruby Interpreter Parse Evaluate

Slide 53

Slide 53 text

How Ruby works Your Code Output Ruby Interpreter Parse Evaluate Syntax Error

Slide 54

Slide 54 text

How Ruby works Your Code Output Ruby Interpreter Parse Evaluate Syntax Error Runtime Error

Slide 55

Slide 55 text

JavaScript

Slide 56

Slide 56 text

Running JS with Ruby console.log("Hello world!"); javascript.rb

Slide 57

Slide 57 text

Running JS with Ruby console.log("Hello world!"); javascript.rb % ruby javascript.rb ??? Terminal

Slide 58

Slide 58 text

Running JS with Ruby console.log("Hello world!"); javascript.rb % ruby javascript.rb ??? Terminal A. It works™

Slide 59

Slide 59 text

Running JS with Ruby console.log("Hello world!"); javascript.rb % ruby javascript.rb ??? Terminal A. It works™ B. Syntax Error

Slide 60

Slide 60 text

Running JS with Ruby console.log("Hello world!"); javascript.rb % ruby javascript.rb ??? Terminal A. It works™ B. Syntax Error C. Runtime Error

Slide 61

Slide 61 text

console.log("Hello world!"); javascript.rb Running JS with Ruby A. It works™ B. Syntax Error C. Runtime Error % ruby javascript.rb NameError: undefined local variable or method `console' for main:Object " from javascript.rb:1 Terminal

Slide 62

Slide 62 text

Running JS with Ruby console.log("Hello world!");

Slide 63

Slide 63 text

Running JS with Ruby console.log("Hello world!"); Local variable (or method) named “console”

Slide 64

Slide 64 text

Running JS with Ruby console.log("Hello world!"); Call instance method “log” on “console”

Slide 65

Slide 65 text

Running JS with Ruby console.log("Hello world!"); Optional parenthesis

Slide 66

Slide 66 text

Running JS with Ruby console.log("Hello world!"); Method argument (String literal “Hello world!”)

Slide 67

Slide 67 text

Running JS with Ruby console.log("Hello world!"); Optional semicolon

Slide 68

Slide 68 text

Running JS with Ruby % ruby javascript.rb NameError: undefined local variable or method `console' for main:Object " from javascript.rb:1 Terminal

Slide 69

Slide 69 text

Running JS with Ruby class Console def log(*args) puts(*args) end end console = Console.new # Begin "JavaScript" console.log("Hello world!"); javascript.rb

Slide 70

Slide 70 text

Running JS with Ruby class Console def log(*args) puts(*args) end end console = Console.new # Begin "JavaScript" console.log("Hello world!"); javascript.rb % ruby javascript.rb Hello world! % Terminal

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Running JS with Ruby class Console def log(*args) puts(*args) end end console = Console.new # Begin "JavaScript" console.log("Hello world!"); javascript.rb % ruby javascript.rb Hello world! % Terminal

Slide 73

Slide 73 text

Running JS with Ruby class Console def log(*args) puts(*args) end end console = Console.new # Begin "JavaScript" console.log("Hello world!"); javascript.rb % ruby javascript.rb Hello world! % Terminal ಠ_ಠ

Slide 74

Slide 74 text

Running JS with Ruby # Magic here... javascript.rb require 'javascript' javascript do console.log("Hello world!"); end hello_world.rb

Slide 75

Slide 75 text

DSLs

Slide 76

Slide 76 text

instance_exec

Slide 77

Slide 77 text

instance_exec module JavaScript class Console; ... ; end class Context def console Console.new end end end module Kernel def javascript(&block) JavaScript::Context.new.instance_exec(&block) end end javascript.rb require 'javascript' javascript do console.log("Hello world!"); end hello_world.rb

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

Variables

Slide 80

Slide 80 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb

Slide 81

Slide 81 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal

Slide 82

Slide 82 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal A. It works™

Slide 83

Slide 83 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal A. It works™ B. Syntax Error

Slide 84

Slide 84 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal A. It works™ B. Syntax Error C. NoMethodError

Slide 85

Slide 85 text

Variables require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal A. It works™ B. Syntax Error C. NoMethodError D. NameError

Slide 86

Slide 86 text

require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb Variables A. It works™ B. Syntax Error C. NoMethodError D. NameError % ruby hello_world.rb NoMethodError: undefined method `var' for # " from hello_world.rb:5 Terminal

Slide 87

Slide 87 text

Variables var message = "Hello world!";

Slide 88

Slide 88 text

Variables var(message = "Hello world!");

Slide 89

Slide 89 text

Variables var(message = "Hello world!"); Optional semicolon

Slide 90

Slide 90 text

Variables var(message = "Hello world!"); Optional parenthesis

Slide 91

Slide 91 text

Variables var(message = "Hello world!"); String literal “Hello world!”

Slide 92

Slide 92 text

Variables var(message = "Hello world!"); Variable assignment

Slide 93

Slide 93 text

Variables var(message = "Hello world!"); Local variable “message”

Slide 94

Slide 94 text

Variables var(message = "Hello world!"); Call method named “var”

Slide 95

Slide 95 text

Variables var(message = "Hello world!"); Variable assignment “returns” the assigned value!

Slide 96

Slide 96 text

Variables message = "Hello world!"; var(message);

Slide 97

Slide 97 text

Variables % ruby hello_world.rb NoMethodError: undefined method `var' for # " from hello_world.rb:5 Terminal

Slide 98

Slide 98 text

Variables module JavaScript ... class Context ... def var(*) end end end ... javascript.rb require 'javascript' javascript do var message = "Hello world!"; console.log(message); end hello_world.rb

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

Uninitialized Variables

Slide 101

Slide 101 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb

Slide 102

Slide 102 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb % ruby hello_world.rb ??? Terminal

Slide 103

Slide 103 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb A. It works™ % ruby hello_world.rb ??? Terminal

Slide 104

Slide 104 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb A. It works™ B. Syntax Error % ruby hello_world.rb ??? Terminal

Slide 105

Slide 105 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError % ruby hello_world.rb ??? Terminal

Slide 106

Slide 106 text

Uninitialized Variables javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError D. NameError % ruby hello_world.rb ??? Terminal

Slide 107

Slide 107 text

javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb Uninitialized Variables A. It works™ B. Syntax Error C. NoMethodError D. NameError % ruby hello_world.rb NameError: undefined local variable or method `message' for " from hello_world.rb:2 Terminal

Slide 108

Slide 108 text

Uninitialized Variables var message; message = "Hello world!";

Slide 109

Slide 109 text

Uninitialized Variables var message(); message = "Hello world!";

Slide 110

Slide 110 text

Uninitialized Variables var(message()); message = "Hello world!";

Slide 111

Slide 111 text

Uninitialized Variables % ruby hello_world.rb NameError: undefined local variable or method `message' for #

Slide 112

Slide 112 text

Uninitialized Variables module JavaScript ... class Context ... def method_missing(*) end end end ... javascript.rb javascript do var message; message = "Hello world!"; console.log(message); end hello_world.rb

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

Functions

Slide 115

Slide 115 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb

Slide 116

Slide 116 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb % ruby hello_world.rb ??? Terminal

Slide 117

Slide 117 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ % ruby hello_world.rb ??? Terminal

Slide 118

Slide 118 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ B. Syntax Error % ruby hello_world.rb ??? Terminal

Slide 119

Slide 119 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError % ruby hello_world.rb ??? Terminal

Slide 120

Slide 120 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError D. NameError % ruby hello_world.rb ??? Terminal

Slide 121

Slide 121 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError D. NameError % ruby hello_world.rb ??? Terminal

Slide 122

Slide 122 text

Functions javascript do function hello() { console.log("Hello world!"); } hello(); end hello_world.rb A. It works™ B. Syntax Error C. NoMethodError D. NameError E. Nothing Happens % ruby hello_world.rb % Terminal

Slide 123

Slide 123 text

Functions function hello() { console.log("Hello world!"); }

Slide 124

Slide 124 text

Functions function hello() { console.log("Hello world!"); } Invoke method “hello”

Slide 125

Slide 125 text

Functions With no “regular” arguments function hello() { console.log("Hello world!"); }

Slide 126

Slide 126 text

Functions ...and a block argument function hello() { console.log("Hello world!"); }

Slide 127

Slide 127 text

Functions ...then invoke the method “function” with its result function hello() { console.log("Hello world!"); }

Slide 128

Slide 128 text

Functions function( hello { console.log("Hello world") } )

Slide 129

Slide 129 text

Functions temp = hello { console.log("Hello world") } function(temp)

Slide 130

Slide 130 text

temp = hello { console.log("Hello world") } function(temp) Functions Undefined methods!

Slide 131

Slide 131 text

Functions temp = hello { console.log("Hello world") } function(temp) ???!

Slide 132

Slide 132 text

Functions module JavaScript class Context def method_missing(*) end end end javascript.rb

Slide 133

Slide 133 text

Functions module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end javascript.rb javascript do function hello() { ... } hello(); end hello_world.rb

Slide 134

Slide 134 text

javascript.rb module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end Functions def method_missing(name, *, &block) end hello_world.rb javascript do function hello() { ... } hello(); end hello() { ... }

Slide 135

Slide 135 text

javascript.rb Functions def method_missing(name, *, &block) if block end hello_world.rb javascript do function hello() { ... } hello(); end hello() { ... } module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end

Slide 136

Slide 136 text

javascript.rb Functions def method_missing(name, *, &block) if block define_singleton_method(name, block) end hello_world.rb javascript do function hello() { ... } hello(); end hello() { ... } module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end

Slide 137

Slide 137 text

javascript.rb Functions hello_world.rb javascript do function hello() { ... } hello(); end function hello() { ... } module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end

Slide 138

Slide 138 text

javascript.rb Functions hello_world.rb javascript do function hello() { ... } hello(); end function hello() { ... } module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end def function(*) end

Slide 139

Slide 139 text

javascript.rb Functions hello_world.rb javascript do function hello() { ... } hello(); end hello(); module JavaScript class Context def function(*) end def method_missing(name, *, &block) if block define_singleton_method(name, block) end end end end

Slide 140

Slide 140 text

No content

Slide 141

Slide 141 text

Function Arguments

Slide 142

Slide 142 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb

Slide 143

Slide 143 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb % ruby hello_world.rb ??? Terminal

Slide 144

Slide 144 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ % ruby hello_world.rb ??? Terminal

Slide 145

Slide 145 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error % ruby hello_world.rb ??? Terminal

Slide 146

Slide 146 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error C. ArgumentError % ruby hello_world.rb ??? Terminal

Slide 147

Slide 147 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error C. ArgumentError D. NameError % ruby hello_world.rb ??? Terminal

Slide 148

Slide 148 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error C. ArgumentError D. NameError E. Nothing Happens % ruby hello_world.rb ??? Terminal

Slide 149

Slide 149 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error C. ArgumentError D. NameError E. Nothing Happens % ruby hello_world.rb ??? Terminal

Slide 150

Slide 150 text

Function Arguments javascript do function hello(name) { console.log("Hello " + name + "!"); } hello("world"); end hello_world.rb A. It works™ B. Syntax Error C. ArgumentError D. NameError E. Nothing Happens % ruby hello_world.rb ??? Terminal

Slide 151

Slide 151 text

No content

Slide 152

Slide 152 text

vanruby/javascript

Slide 153

Slide 153 text

Such tests! test "Functions can return a value" do require "javascript" javascript { function identity(x) { return x; } function square(x) { return x * x; } console.log(identity("Hello world!")); console.log(square(2)); } assert_messages "Hello world!", 4 end

Slide 154

Slide 154 text

ಠ_ಠ

Slide 155

Slide 155 text

Why?

Slide 156

Slide 156 text

¯\_(π)_/¯

Slide 157

Slide 157 text

Why not?

Slide 158

Slide 158 text

@chancancode