Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our...

34
Modeling Process Rich Hickey

Transcript of Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our...

Page 1: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Modeling Process

Rich Hickey

Page 2: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Which are more fundamental?

•Messages, classes, encapsulation, inheritance, dispatch...

•Time, value, identity, state, persistence, transience, place, perception, visibility, memory, process...

Page 3: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Coming to TermsValue

• An immutable magnitude, quantity, number... or immutable composite thereof

Identity

• A putative entity we associate with a series of causally related values (states) over time

State

• Value of an identity at a moment in time

Time

• Relative before/after ordering of causal values

Page 4: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

A Real Problem

Page 5: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Place• “open space”

• Relative

• Include time coordinate, and process results happen in new places

Page 6: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

What Would a Program Do?

Not this!

Page 7: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Are places in charge?

Page 8: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

What do we see?

Page 9: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Our Problem

MemoryPerception

Reality

Logic

Page 10: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Perception• Perceive - “take entirely”

• Sensory systems only ever perceive the past

• Discretizing, snapshots

• Most useful when coupled with memory

• Fidelity matters

• Visible == “can be perceived”

• not merely ‘reachable via reference’

Page 11: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Memory• “mindful, remembering”

• If our mental memory behaved the way we use computer memory, we’d be ill

• In the mind we talk about forming memories

• New memories about the same identities don’t replace the old

• Fidelity matters

• Stability matters (persistence)

Page 12: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Program Memory

• Sometimes we use computer memory like brain memory

• Sometimes like perception

• Sometimes (commonly, most of the time) like places

Page 13: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Using the same memory for everything

• Destroys the past

• Corrupts remembering

• Interferes with perception

• We must use memory for all three things, but not necessarily the same memory

Page 14: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Process

Page 15: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Process

• “go forward, advance”

• They’re not called “food calculators”

• Potentially richer than this

• Manipulate contents of place(s)

• May involve multiple forces

Page 16: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Process across multiple places

Page 17: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Process with multiple forces/participants

Page 18: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Philosophy• Things don't change in place

• Becomes obvious once you incorporate time as a dimension

• Place includes time

• The future is a (multi-force) function of the past

• Co-located entities can observe each other without cooperation

• Coordination is desirable in local context

Page 19: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

� �

� �

� �

� �

Process events (pure functions*)

Observers/perception/memory

States (immutable values)Identity

(succession of states)

Epochal Time Model

Page 20: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Persistent

• “lasting or enduring tenaciously”

• Root: “to stand firm permanently”

• When applied to data structures

• A) safe on the disk (not today’s topic)

• B) immutable++

• Great fit for perceptions and memories

Page 21: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Identity Constructs as Gatekeepers of Time

• Responsible for coherent successive states

• Multiple semantics possible

• And providing proper values to observers

• Support coordination (multiple places) and process functions supplied from multiple threads of control (multiple participants)

Page 22: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

v2

Fn + args

v3

Functional Model

Page 23: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

23

• 1:1 timeline/identity

• Atomic state succession

• Point-in-time value perception

F

v2

F

v3

F

v4

vN+1

vNs

vN

AtomicReference

(swap! an-atom f args)

(f vN args) becomes vN+1

- can automate spin

CAS as Time Construct

Page 24: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

24

• 1:1 timeline/identity

• Atomic state succession

• Point-in-time value perception

(send aref f args)returns immediately

queue enforces serialization

(f vN args) becomes vN+1

happens asynchronously in thread pool thread

Agents as Time ConstructF

vN+1

vNs

vN

F FFFF

Page 25: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

F

v1 v2 v3 v4

v1 v2 v3 v4

v1 v2 v3 v4

v1 v2 v3 v4

F

F

F

F

F

F

F F F

F

F

Transactions

STM as Time Construct

25

Page 26: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

But...

• What if my logical unit of work involves a million steps?

• Creating a million interim values via pure function invocation is a waste

• “I’m going back to my cubbyholes!”

Page 27: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Transient• “not lasting, enduring, or permanent;

transitory”

• Root: “go across”

• When applied to data structures:

• Not persistent!

• Each operation returns the next transient

• Can’t presume modify-in-place

• Doesn’t preclude it either

• No identity

Page 28: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Transient-Based Model

v2

Proc + args

v3aTransient

Proc + args

aTransientaTransient

Make Transient(in new memory)

can be O(1)

Make Persistent (immutable)can be O(1)

Page 29: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

What about those Procs?

• Might modify their arguments

• Isn’t this just icky mutable side-effecting coding again?

• hard to test

• difficult to reason about

• No!

Page 30: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Proc• Function of transient to transient

• Like pure function, can’t effect the world nor be effected by it

• Only used in a context where transient cannot leak

• Can always be sandwiched in value->transient and transient->value functions and become ‘pure’

Pure Function

ProcV->T T->Vvalue value

Page 31: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

The sweet, creamy, efficient middle of pure

functions

Page 32: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Transient/Proc Model• Prototype implementation - ‘pods’

• Can support multiple participants, in multiple threads

• and coordination of multiple identities/places

• even ad hoc grouping

• But not arbitrary composition/nesting

• Same limitation as locks, but detectable

• Agents could support as well

Page 33: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Summary

• We need to talk about these things

• Better, more precise language and terms

• Language and library support

• Examine high-level abstractions and constructs in terms of these fundamental issues

Page 34: Modeling Process - GOTO Conferencegotocon.com/dl/jaoo-aarhus-2010/slides/RichHickey... · Our Problem Memory Perception Reality Logic. Perception ... • Things don't change in place

Thanks for listening!

http://clojure.org