Modeling Process Rich Hickey Which are more fundamental? - - PowerPoint PPT Presentation

modeling process
SMART_READER_LITE
LIVE PREVIEW

Modeling Process Rich Hickey Which are more fundamental? - - PowerPoint PPT Presentation

Modeling Process Rich Hickey Which are more fundamental? Messages, classes, encapsulation, inheritance, dispatch... Time, value, identity, state, persistence, transience, place, perception, visibility, memory, process... Coming to


slide-1
SLIDE 1

Modeling Process

Rich Hickey

slide-2
SLIDE 2

Which are more fundamental?

  • Messages, classes, encapsulation,

inheritance, dispatch...

  • Time, value, identity, state,

persistence, transience, place, perception, visibility, memory, process...

slide-3
SLIDE 3

Coming to Terms

Value

  • 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
  • rdering of causal values
slide-4
SLIDE 4

A Real Problem

slide-5
SLIDE 5

Place

  • “open space”
  • Relative
  • Include time coordinate, and process

results happen in new places

slide-6
SLIDE 6

What Would a Program Do?

Not this!

slide-7
SLIDE 7

Are places in charge?

slide-8
SLIDE 8

What do we see?

slide-9
SLIDE 9

Our Problem

Memory Perception Reality Logic

slide-10
SLIDE 10

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’
slide-11
SLIDE 11

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)
slide-12
SLIDE 12

Program Memory

  • Sometimes we use computer memory like

brain memory

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

like places

slide-13
SLIDE 13

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

slide-14
SLIDE 14

Process

slide-15
SLIDE 15

Process

  • “go forward, advance”
  • They’re not called “food calculators”
  • Potentially richer than this
  • Manipulate contents of place(s)
  • May involve multiple forces
slide-16
SLIDE 16

Process across multiple places

slide-17
SLIDE 17

Process with multiple forces/participants

slide-18
SLIDE 18

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
slide-19
SLIDE 19
  • Process events

(pure functions*)

Observers/perception/memory

States (immutable values)

Identity (succession of states)

Epochal Time Model

slide-20
SLIDE 20

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
slide-21
SLIDE 21

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)

slide-22
SLIDE 22

v2 Fn + args v3

Functional Model

slide-23
SLIDE 23

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

slide-24
SLIDE 24

24

  • 1:1 timeline/identity
  • Atomic state succession
  • Point-in-time value

perception

( s e n d a r e f f a r g s )

returns immediately queue enforces serialization

( f v N a r g s ) becomes vN+1

happens asynchronously in thread pool thread

Agents as Time Construct

F vN+1 vNs vN F F F F F

slide-25
SLIDE 25

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

slide-26
SLIDE 26

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!”
slide-27
SLIDE 27

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
slide-28
SLIDE 28

Transient-Based Model

v2 Proc + args v3

aTransient

P r

  • c

+ a r g s

aTransient aTransient

Make Transient (in new memory) can be O(1) Make Persistent (immutable) can be O(1)

slide-29
SLIDE 29

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!
slide-30
SLIDE 30

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 Proc V->T T->V value value

slide-31
SLIDE 31

The sweet, creamy, efficient middle of pure functions

slide-32
SLIDE 32

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
slide-33
SLIDE 33

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

slide-34
SLIDE 34

Thanks for listening!

http://clojure.org