116
Ruby After 18+ Months of Clojure -or- Functional Learnings of Clojure for Make Benefit of Glorious Language of Ruby* (a work in progress) Brian Marick, Path11 [email protected] , @marick 1 *Alternate title courtesy @infinitary Wednesday, January 18, 2012

Ruby after 18+ months of Clojure

  • View
    3.894

  • Download
    2

Embed Size (px)

DESCRIPTION

Slides for February 17 Groupon geekfest lunch

Citation preview

Page 1: Ruby after 18+ months of Clojure

Ruby After 18+ Months of Clojure

-or-

Functional Learnings of Clojure for Make Benefit of Glorious Language of Ruby*

(a work in progress)

Brian Marick, [email protected], @marick

1 *Alternate title courtesy @infinitaryWednesday, January 18, 2012

Page 2: Ruby after 18+ months of Clojure

Ladies and Gentlemen: The Computer

Wednesday, January 18, 2012

Page 3: Ruby after 18+ months of Clojure

Wednesday, January 18, 2012

Page 4: Ruby after 18+ months of Clojure

Wednesday, January 18, 2012

Page 5: Ruby after 18+ months of Clojure

Wednesday, January 18, 2012

Page 6: Ruby after 18+ months of Clojure

4

f()g()

h()

j()

k()

m()

width

height

colorscofield_v

Our Friend, the Class

Wednesday, January 18, 2012

Page 7: Ruby after 18+ months of Clojure

What Are Classes Good For?

5

Wednesday, January 18, 2012

Page 8: Ruby after 18+ months of Clojure

What Are Classes Good For?

5

Wednesday, January 18, 2012

Page 9: Ruby after 18+ months of Clojure

6

The Real World Has Fuzzy Categories

Wednesday, January 18, 2012

Page 10: Ruby after 18+ months of Clojure

6

The Real World Has Fuzzy Categories

Wednesday, January 18, 2012

Page 11: Ruby after 18+ months of Clojure

7

f()g()

h()

j()

k()

m()

width

height

colorscofield_v

Classes Are For Finding Things

Wednesday, January 18, 2012

Page 12: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

Wednesday, January 18, 2012

Page 13: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs { } [ ] ( )

Wednesday, January 18, 2012

Page 14: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs { } [ ] ( )

Wednesday, January 18, 2012

Page 15: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs { } [ ] ( )

Wednesday, January 18, 2012

Page 16: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs { } [ ] ( )

Wednesday, January 18, 2012

Page 17: Ruby after 18+ months of Clojure

Classes Are For Finding Things

8

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs

wh

cs { } [ ] ( )

But At What Cost?

Wednesday, January 18, 2012

Page 18: Ruby after 18+ months of Clojure

9

Wednesday, January 18, 2012

Page 19: Ruby after 18+ months of Clojure

10

Lookup

Wednesday, January 18, 2012

Page 20: Ruby after 18+ months of Clojure

10

Lookup

Wednesday, January 18, 2012

Page 21: Ruby after 18+ months of Clojure

11

Wednesday, January 18, 2012

Page 22: Ruby after 18+ months of Clojure

12

?

Lookup

Copy

Wednesday, January 18, 2012

Page 23: Ruby after 18+ months of Clojure

12

?

Lookup

Copy

Wednesday, January 18, 2012

Page 24: Ruby after 18+ months of Clojure

12

?

Lookup

Copy

Wednesday, January 18, 2012

Page 25: Ruby after 18+ months of Clojure

13

Wednesday, January 18, 2012

Page 26: Ruby after 18+ months of Clojure

13

Do The Simplest Thing That Could

Possibly Work

Wednesday, January 18, 2012

Page 27: Ruby after 18+ months of Clojure

14

ActiveRecord

Wednesday, January 18, 2012

Page 28: Ruby after 18+ months of Clojure

14

ActiveRecord

Wait. What?

Wednesday, January 18, 2012

Page 29: Ruby after 18+ months of Clojure

id

uses

ctimesliceLookup

15

Copy

Wednesday, January 18, 2012

Page 30: Ruby after 18+ months of Clojure

id

uses

ctimeslice

Lookup

15

Copy

Wednesday, January 18, 2012

Page 31: Ruby after 18+ months of Clojure

Lookup

16

id

uses

ctimeslice

Copy

Wednesday, January 18, 2012

Page 32: Ruby after 18+ months of Clojure

Lookup

16

id

uses

ctimeslice

Copy

Wednesday, January 18, 2012

Page 33: Ruby after 18+ months of Clojure

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

Page 34: Ruby after 18+ months of Clojure

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

Page 35: Ruby after 18+ months of Clojure

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

Page 36: Ruby after 18+ months of Clojure

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu cti

Copy

Wednesday, January 18, 2012

Page 37: Ruby after 18+ months of Clojure

copy comitted_animals

Lookup

18

id

use ctim

idu cti

idu cti

Copy

Wednesday, January 18, 2012

Page 38: Ruby after 18+ months of Clojure

Lookup

18

Copy

Wednesday, January 18, 2012

Page 39: Ruby after 18+ months of Clojure

19

Copy

Lookup

Wednesday, January 18, 2012

Page 40: Ruby after 18+ months of Clojure

19

Copy

Lookup

Wednesday, January 18, 2012

Page 41: Ruby after 18+ months of Clojure

20

Wednesday, January 18, 2012

Page 42: Ruby after 18+ months of Clojure

20

Wednesday, January 18, 2012

Page 43: Ruby after 18+ months of Clojure

Lookup

21

Copy

Wednesday, January 18, 2012

Page 44: Ruby after 18+ months of Clojure

Lookup

21

Copy

Wednesday, January 18, 2012

Page 45: Ruby after 18+ months of Clojure

22

and...

Wednesday, January 18, 2012

Page 46: Ruby after 18+ months of Clojure

22

and...

Wednesday, January 18, 2012

Page 47: Ruby after 18+ months of Clojure

23

Wednesday, January 18, 2012

Page 48: Ruby after 18+ months of Clojure

23

{ }

Wednesday, January 18, 2012

Page 49: Ruby after 18+ months of Clojure

23

{ }

Wednesday, January 18, 2012

Page 50: Ruby after 18+ months of Clojure

24

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }{ }

Wednesday, January 18, 2012

Page 51: Ruby after 18+ months of Clojure

25

Wednesday, January 18, 2012

Page 52: Ruby after 18+ months of Clojure

25

Wednesday, January 18, 2012

Page 53: Ruby after 18+ months of Clojure

26

Wednesday, January 18, 2012

Page 54: Ruby after 18+ months of Clojure

27

Wednesday, January 18, 2012

Page 55: Ruby after 18+ months of Clojure

27

Wednesday, January 18, 2012

Page 56: Ruby after 18+ months of Clojure

Immutability

28

Wednesday, January 18, 2012

Page 57: Ruby after 18+ months of Clojure

Immutability

28

Wednesday, January 18, 2012

Page 58: Ruby after 18+ months of Clojure

Immutability

28

Wednesday, January 18, 2012

Page 59: Ruby after 18+ months of Clojure

29

Hygiene

Wednesday, January 18, 2012

Page 60: Ruby after 18+ months of Clojure

29

Hygiene

“You’ve slept with everyoneeveryone you’ve ever slept with

ever slept with.”

Wednesday, January 18, 2012

Page 61: Ruby after 18+ months of Clojure

29

Hygiene

“You’ve slept with everyoneeveryone you’ve ever slept with

ever slept with.”

“Your code might be infected by any code that has ever touched your data.”

Wednesday, January 18, 2012

Page 62: Ruby after 18+ months of Clojure

29

a=Hygiene

“You’ve slept with everyoneeveryone you’ve ever slept with

ever slept with.”

“Your code might be infected by any code that has ever touched your data.”

Wednesday, January 18, 2012

Page 63: Ruby after 18+ months of Clojure

29

a=

a

Hygiene

“You’ve slept with everyoneeveryone you’ve ever slept with

ever slept with.”

“Your code might be infected by any code that has ever touched your data.”

Wednesday, January 18, 2012

Page 64: Ruby after 18+ months of Clojure

29

a=

a

Hygiene

“You’ve slept with everyoneeveryone you’ve ever slept with

ever slept with.”

“Your code might be infected by any code that has ever touched your data.”

Wednesday, January 18, 2012

Page 65: Ruby after 18+ months of Clojure

30

Consequences

Wednesday, January 18, 2012

Page 66: Ruby after 18+ months of Clojure

30

Consequences

Wednesday, January 18, 2012

Page 67: Ruby after 18+ months of Clojure

31

5

Consequences

Wednesday, January 18, 2012

Page 68: Ruby after 18+ months of Clojure

32

Consequences

5

Wednesday, January 18, 2012

Page 69: Ruby after 18+ months of Clojure

32

Consequences

5

Wednesday, January 18, 2012

Page 70: Ruby after 18+ months of Clojure

32

Consequences

5

Wednesday, January 18, 2012

Page 71: Ruby after 18+ months of Clojure

33

Wednesday, January 18, 2012

Page 72: Ruby after 18+ months of Clojure

In Short: Why Not?

34

Wednesday, January 18, 2012

Page 73: Ruby after 18+ months of Clojure

In Short: Why Not?

34

• Removes one source of bugs

Wednesday, January 18, 2012

Page 74: Ruby after 18+ months of Clojure

In Short: Why Not?

34

• Removes one source of bugs

• Not harder than coding mutably

• (once you’re used to it)

Wednesday, January 18, 2012

Page 75: Ruby after 18+ months of Clojure

In Short: Why Not?

34

• Removes one source of bugs

• Not harder than coding mutably

• (once you’re used to it)

• Knowing how to do more is better than knowing how to do less

Wednesday, January 18, 2012

Page 76: Ruby after 18+ months of Clojure

Ruby

35

Wednesday, January 18, 2012

Page 77: Ruby after 18+ months of Clojure

Ruby

35

Wednesday, January 18, 2012

Page 78: Ruby after 18+ months of Clojure

Ruby

35

Haskell

Wednesday, January 18, 2012

Page 79: Ruby after 18+ months of Clojure

Ruby

35

Haskell

Wednesday, January 18, 2012

Page 80: Ruby after 18+ months of Clojure

Ruby

35

Haskell Always Lazy

Wednesday, January 18, 2012

Page 81: Ruby after 18+ months of Clojure

Ruby

35

Haskell Always Lazy

Mostly Eager

Wednesday, January 18, 2012

Page 82: Ruby after 18+ months of Clojure

Some Lazy Ruby

36

Wednesday, January 18, 2012

Page 83: Ruby after 18+ months of Clojure

37

Some Lazy Ruby

Wednesday, January 18, 2012

Page 84: Ruby after 18+ months of Clojure

37

Only a few special Ruby operators are lazy

Some Lazy Ruby

Wednesday, January 18, 2012

Page 85: Ruby after 18+ months of Clojure

And Why Not?

38

Wednesday, January 18, 2012

Page 86: Ruby after 18+ months of Clojure

And Why Not?

39

Wednesday, January 18, 2012

Page 87: Ruby after 18+ months of Clojure

40

a=

Wednesday, January 18, 2012

Page 88: Ruby after 18+ months of Clojure

40

a=

Wednesday, January 18, 2012

Page 89: Ruby after 18+ months of Clojure

40

a=

a

a

Wednesday, January 18, 2012

Page 90: Ruby after 18+ months of Clojure

40

a=

a

a

Wednesday, January 18, 2012

Page 91: Ruby after 18+ months of Clojure

40

a=

a

a

Wednesday, January 18, 2012

Page 92: Ruby after 18+ months of Clojure

40

a=

a

a

Wednesday, January 18, 2012

Page 93: Ruby after 18+ months of Clojure

40

a=

a

a

OneLessThing

toWorryAbout

Wednesday, January 18, 2012

Page 94: Ruby after 18+ months of Clojure

41

Wednesday, January 18, 2012

Page 95: Ruby after 18+ months of Clojure

42

a=

a

a

free(a)

Wednesday, January 18, 2012

Page 96: Ruby after 18+ months of Clojure

42

a=

a

a

Wednesday, January 18, 2012

Page 97: Ruby after 18+ months of Clojure

43

a

a

a=

Wednesday, January 18, 2012

Page 98: Ruby after 18+ months of Clojure

44

Wednesday, January 18, 2012

Page 99: Ruby after 18+ months of Clojure

44

OMG!!! As Big As Garbage

Collection???

Wednesday, January 18, 2012

Page 100: Ruby after 18+ months of Clojure

44

OMG!!! As Big As Garbage

Collection???CalculationsYou Trace

Through Time

Wednesday, January 18, 2012

Page 101: Ruby after 18+ months of Clojure

44

OMG!!! As Big As Garbage

Collection???Resources You

ConsumeAs Needed

CalculationsYou Trace

Through Time

Wednesday, January 18, 2012

Page 102: Ruby after 18+ months of Clojure

45

Lazy Sequences

Wednesday, January 18, 2012

Page 103: Ruby after 18+ months of Clojure

45

Lazy Sequences

Wednesday, January 18, 2012

Page 104: Ruby after 18+ months of Clojure

45

Lazy Sequences

Wednesday, January 18, 2012

Page 105: Ruby after 18+ months of Clojure

46

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 106: Ruby after 18+ months of Clojure

46

How toMake theNext One

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 107: Ruby after 18+ months of Clojure

46

How toMake theNext One

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 108: Ruby after 18+ months of Clojure

46

How toMake theNext One

WhichOnes

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 109: Ruby after 18+ months of Clojure

46

How toMake theNext One

WhichOnes

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 110: Ruby after 18+ months of Clojure

LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 111: Ruby after 18+ months of Clojure

LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

Page 112: Ruby after 18+ months of Clojure

LikeWhat You Get With Lazy Sequences

How toMake the Next One

Wednesday, January 18, 2012

Page 113: Ruby after 18+ months of Clojure

LikeWhat You Get With Lazy Sequences

How toMake the Next One

WhichOnes

Wednesday, January 18, 2012

Page 114: Ruby after 18+ months of Clojure

48

github.com/marick/stunted

Google groups:rubyfoopers

Wednesday, January 18, 2012

Page 115: Ruby after 18+ months of Clojure

object.f(2, 3, 4)

def Float, Integer ...def Integer, Float

f.(2.0, 2)

49

Wednesday, January 18, 2012

Page 116: Ruby after 18+ months of Clojure

50

Google groups:rubyfoopers

github.com/marick/stunted

ExpressivenessEfficiency

Gems

Wednesday, January 18, 2012