Immutability Talks

 Immutability Talks

 

LEE BRYON of Facebook

Immutability - copy rather than change
  power (goto) vs. principles (loops, even reduce, etc.)
  declarative (what not how)

Show changes by making more changes
Latency, Intermittency, and Failure
REST - fires loading of subtables

Architecture:
  old: MVC and REST
  new: Immutable, Declarative, Executable, Architecture

Views:
  View Trees that are mutatable  
  Models are data (via server) => (old) Components => (old) render into Views
  React Native, Component Kit, Litho:    Pure Functional - Javascript functions
                                         then Mutable Objects - DOM elements (View)
  new is GraphQL and fragments

Structural sharing for performance
Persistence immutable data structures - Immutable.js used in Robin Hood
Easy undos and redos.

Memoization - call function and parameter values same as last time then just return same answer as last time

Action
  Server: (State) => Promise<State>
  Optimistic: (State) => State

Action State Race Conditions - Queue for actions

True State   Action Queue   Optimistic State
State 1      [ActA]          ActA(State1)
             [ActA, ActB]    ActB(ActA(State1))
State 2      [ActB]          ActB(State2)
State 3      []              State3

Immutable and Declarative

Newsfeed at Facebook

=========================================

RICHARD FELDMAN

Distributive systems - Synchronization (Publisher, Subscriber)
 
Problem: "Multiple Sources of Truth"
  1) ex: record - immutable while JS has mutable references

MUTABLE REFERENCES IN JS:
  courses[0].students[0]
   { name: "Richard Feldman", going: true }
  courses[1].students[0]
   { name: "Richard Feldman", going: true }

 so either one would change.

  2) ex: JSON is immutable while JS Object has mutable references

so mutable references (like objects) have implicit synchronization
while immutable references (like records) have cheap copy and equality check

bad structure:
   types alias Student = { name: string, going: bool }
   types alias Course =  { name: string, students: List Student }
   types alias Model =  { courses: List course }

bad JSON:
   { courses: [
     { "name": "2nd period English", "students": [{name: "Richard Feldman", going: true}] },
     { "name": "5th period History", "students": [{name: "Richard Feldman", going: false}] }
    ]
  }

fix structure:
   types alias Student = { name: string, going: bool }
   types alias Course =  { name: string, studentIds: List StudentIds OR better yet Set StudentId }
   types alias Model =  { courses: List course, students: Dict StudentId Student }

fix for JSON (explicit identifiers):
 { courses: [
     { "name": "2nd period English", "students": [217] },
     { "name": "5th period History", "students": [217] }
    ],
   students: {"217": {name: "Richard Feldman", going: false}}
  }
       
Dictionaries as tables
  SELECT   ....   get
  WHERE    ....   filter
  JOIN     ....   intersect

  Dict.filter isVotingAge user |> Dict.size
  locals = Dict.filter (\userId city -> city.name == "STL") residents
 
  Dict.filter isVotingAge model.users
     |> Dict.intersect locals
     |> Dict.size

=========================================

 Ryan Chenkie

const getQuerySelections = {{ fieldNodes }} => {
    return fieldNodes
      .map(node => node.selectionSet.selections)
      .flat()
      .map(s => s.name.value)
      .join(' ');
};

 

Comments

Popular posts from this blog

Upgrading to .NET8 from desktop versions 4.8.X

GHL Chat Bots for Webpage

GHL > Set website so shorter URL address