Ruby after 18+ months of Clojure

Preview:

DESCRIPTION

Slides for February 17 Groupon geekfest lunch

Citation preview

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, Path11brian@path11.com, @marick

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

Ladies and Gentlemen: The Computer

Wednesday, January 18, 2012

Wednesday, January 18, 2012

Wednesday, January 18, 2012

Wednesday, January 18, 2012

4

f()g()

h()

j()

k()

m()

width

height

colorscofield_v

Our Friend, the Class

Wednesday, January 18, 2012

What Are Classes Good For?

5

Wednesday, January 18, 2012

What Are Classes Good For?

5

Wednesday, January 18, 2012

6

The Real World Has Fuzzy Categories

Wednesday, January 18, 2012

6

The Real World Has Fuzzy Categories

Wednesday, January 18, 2012

7

f()g()

h()

j()

k()

m()

width

height

colorscofield_v

Classes Are For Finding Things

Wednesday, January 18, 2012

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

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

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

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

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

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

9

Wednesday, January 18, 2012

10

Lookup

Wednesday, January 18, 2012

10

Lookup

Wednesday, January 18, 2012

11

Wednesday, January 18, 2012

12

?

Lookup

Copy

Wednesday, January 18, 2012

12

?

Lookup

Copy

Wednesday, January 18, 2012

12

?

Lookup

Copy

Wednesday, January 18, 2012

13

Wednesday, January 18, 2012

13

Do The Simplest Thing That Could

Possibly Work

Wednesday, January 18, 2012

14

ActiveRecord

Wednesday, January 18, 2012

14

ActiveRecord

Wait. What?

Wednesday, January 18, 2012

id

uses

ctimesliceLookup

15

Copy

Wednesday, January 18, 2012

id

uses

ctimeslice

Lookup

15

Copy

Wednesday, January 18, 2012

Lookup

16

id

uses

ctimeslice

Copy

Wednesday, January 18, 2012

Lookup

16

id

uses

ctimeslice

Copy

Wednesday, January 18, 2012

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu ctiCopy

Wednesday, January 18, 2012

copy comitted_animals

Lookup

17

id

use ctim

idu cti

idu cti

Copy

Wednesday, January 18, 2012

copy comitted_animals

Lookup

18

id

use ctim

idu cti

idu cti

Copy

Wednesday, January 18, 2012

Lookup

18

Copy

Wednesday, January 18, 2012

19

Copy

Lookup

Wednesday, January 18, 2012

19

Copy

Lookup

Wednesday, January 18, 2012

20

Wednesday, January 18, 2012

20

Wednesday, January 18, 2012

Lookup

21

Copy

Wednesday, January 18, 2012

Lookup

21

Copy

Wednesday, January 18, 2012

22

and...

Wednesday, January 18, 2012

22

and...

Wednesday, January 18, 2012

23

Wednesday, January 18, 2012

23

{ }

Wednesday, January 18, 2012

23

{ }

Wednesday, January 18, 2012

24

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }

{ }{ }

Wednesday, January 18, 2012

25

Wednesday, January 18, 2012

25

Wednesday, January 18, 2012

26

Wednesday, January 18, 2012

27

Wednesday, January 18, 2012

27

Wednesday, January 18, 2012

Immutability

28

Wednesday, January 18, 2012

Immutability

28

Wednesday, January 18, 2012

Immutability

28

Wednesday, January 18, 2012

29

Hygiene

Wednesday, January 18, 2012

29

Hygiene

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

ever slept with.”

Wednesday, January 18, 2012

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

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

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

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

30

Consequences

Wednesday, January 18, 2012

30

Consequences

Wednesday, January 18, 2012

31

5

Consequences

Wednesday, January 18, 2012

32

Consequences

5

Wednesday, January 18, 2012

32

Consequences

5

Wednesday, January 18, 2012

32

Consequences

5

Wednesday, January 18, 2012

33

Wednesday, January 18, 2012

In Short: Why Not?

34

Wednesday, January 18, 2012

In Short: Why Not?

34

• Removes one source of bugs

Wednesday, January 18, 2012

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

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

Ruby

35

Wednesday, January 18, 2012

Ruby

35

Wednesday, January 18, 2012

Ruby

35

Haskell

Wednesday, January 18, 2012

Ruby

35

Haskell

Wednesday, January 18, 2012

Ruby

35

Haskell Always Lazy

Wednesday, January 18, 2012

Ruby

35

Haskell Always Lazy

Mostly Eager

Wednesday, January 18, 2012

Some Lazy Ruby

36

Wednesday, January 18, 2012

37

Some Lazy Ruby

Wednesday, January 18, 2012

37

Only a few special Ruby operators are lazy

Some Lazy Ruby

Wednesday, January 18, 2012

And Why Not?

38

Wednesday, January 18, 2012

And Why Not?

39

Wednesday, January 18, 2012

40

a=

Wednesday, January 18, 2012

40

a=

Wednesday, January 18, 2012

40

a=

a

a

Wednesday, January 18, 2012

40

a=

a

a

Wednesday, January 18, 2012

40

a=

a

a

Wednesday, January 18, 2012

40

a=

a

a

Wednesday, January 18, 2012

40

a=

a

a

OneLessThing

toWorryAbout

Wednesday, January 18, 2012

41

Wednesday, January 18, 2012

42

a=

a

a

free(a)

Wednesday, January 18, 2012

42

a=

a

a

Wednesday, January 18, 2012

43

a

a

a=

Wednesday, January 18, 2012

44

Wednesday, January 18, 2012

44

OMG!!! As Big As Garbage

Collection???

Wednesday, January 18, 2012

44

OMG!!! As Big As Garbage

Collection???CalculationsYou Trace

Through Time

Wednesday, January 18, 2012

44

OMG!!! As Big As Garbage

Collection???Resources You

ConsumeAs Needed

CalculationsYou Trace

Through Time

Wednesday, January 18, 2012

45

Lazy Sequences

Wednesday, January 18, 2012

45

Lazy Sequences

Wednesday, January 18, 2012

45

Lazy Sequences

Wednesday, January 18, 2012

46

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

46

How toMake theNext One

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

46

How toMake theNext One

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

46

How toMake theNext One

WhichOnes

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

46

How toMake theNext One

WhichOnes

Don’t LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

LikeWhat You Get With Lazy Sequences

Wednesday, January 18, 2012

LikeWhat You Get With Lazy Sequences

How toMake the Next One

Wednesday, January 18, 2012

LikeWhat You Get With Lazy Sequences

How toMake the Next One

WhichOnes

Wednesday, January 18, 2012

48

github.com/marick/stunted

Google groups:rubyfoopers

Wednesday, January 18, 2012

object.f(2, 3, 4)

def Float, Integer ...def Integer, Float

f.(2.0, 2)

49

Wednesday, January 18, 2012

50

Google groups:rubyfoopers

github.com/marick/stunted

ExpressivenessEfficiency

Gems

Wednesday, January 18, 2012