Slide 1

Slide 1 text

TIME AND CONCURRENCY PROGRAMMING PARADIGMS AND THE FAILURE OF STATE Jason Lewis @canweriotnow Yet Analytics

Slide 2

Slide 2 text

HELLO I think I was destined to become a functional programmer.

Slide 3

Slide 3 text

Some years ago

Slide 4

Slide 4 text

I spraypainted liked graffiti like this...

Slide 5

Slide 5 text

...and ended up here.

Slide 6

Slide 6 text

TIME WE HAVE PROBLEMS WITH: State Value Identity

Slide 7

Slide 7 text

You could not step twice into the same river. — Heraclitus of Ephesus

Slide 8

Slide 8 text

PROBLEMS ARE BOTH: In our programs In our datastores

Slide 9

Slide 9 text

THERE ARE SOLUTIONS Clojure Datomic (of which these are but two)

Slide 10

Slide 10 text

WHAT IS IT?

Slide 11

Slide 11 text

AN EXPERT EXPLAINS 0:18

Slide 12

Slide 12 text

TIME PERCEPTION

Slide 13

Slide 13 text

REALITY

Slide 14

Slide 14 text

CONCURRENCY Really, ( > = t h i n g s 3 ) Concurrency Parallellism Distributed systems ...

Slide 15

Slide 15 text

CONCURRENCY Object-Oriented (stateful): Stateful objects Mutexes and locking No (realistic) notion of time

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Functional: Pure fns are timeless Zero state Run anywhen, anywhere, same result

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

CLOJURE(SCRIPT) Emphasis on pure functions Persistent data structures Side-effects are allowed State is managed

Slide 20

Slide 20 text

Web programming IS distributed systems programming.

Slide 21

Slide 21 text

Even in the simplest web application, we need to consider at least 3 things: the server, the browser, and the user.

Slide 22

Slide 22 text

One language, two hosts: JVM (server) JS (browser)

Slide 23

Slide 23 text

Code Sharing ( d e f n s t r - > i n t [ s ] # ? ( : c l j ( j a v a . l a n g . I n t e g e r / p a r s e I n t s ) : c l j s ( j s / p a r s e I n t s ) ) )

Slide 24

Slide 24 text

DATOMIC EAVT tuple store database. ACID transactions. Immutable data = strong consistency + horizontal read scalability. Writes are not update-in-place; all data is retained by default. Makes time part of the database itself.

Slide 25

Slide 25 text

BIG WIN: TIME TRAVEL

Slide 26

Slide 26 text

Since Datomic retains the history of the db state, we can query the db as-of any given point in time. Since it treats the db as a value, and uses the same persistent data structures as Clojure itself, we can also query the future, by joining arbitrary data to a given db value.

Slide 27

Slide 27 text

IT GETS BETTER... ( q ' [ : f i n d ? t i t l e : w h e r e [ ? e : m o v i e / y e a r 1 9 8 7 ] [ ? e : m o v i e / t i t l e ? t i t l e ] ] ) Datomic's datalog queries are just vectors, which means they can be passed around like any other of Clojure's persistent data structures... even from the browser to the server.

Slide 28

Slide 28 text

PUTTING IT ALL TOGETHER

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Pure functions acting on immutable data structures shared between client and server. Peers keep a hot copy of the db as a value in memory Reads and writes are orthogonal

Slide 31

Slide 31 text

Time = λ

Slide 32

Slide 32 text

Baltimore Clojure Meetup http://is.gd/baltimoreclojure

Slide 33

Slide 33 text

THANK YOU! Jason Lewis Yet Analytics @canweriotnow jason@yetanalytics.com