Skip to content

Instantly share code, notes, and snippets.

@beppu
Created September 20, 2014 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beppu/cd5e0be8a2d9aea3303d to your computer and use it in GitHub Desktop.
Save beppu/cd5e0be8a2d9aea3303d to your computer and use it in GitHub Desktop.

The Strange Loop 2014

Welcome

cross pollination

diversity

90 diversity scholarships

talk to people

expand your horizons

Keynote - Joe Armstrong - Erlang

Friday, he had a bad day.

New version of open office.

Tried to add images. All images disappeared.

Apple’s Keynote was broken for him too. (diff versions not compatible)

Decided to do slides in HTML

Doesn’t produce nice PDFs for later download though.

Found one that did, but needed grunt.

Installed grunt, but wasn’t in his path. Very confusing.

He’s been programming since 1965.

1948

Tom Kilburn; first modern programmer? June 21, 1948 - first program.

1985

That’s when he started work on Erlang.

Compared 1985 vs 2014 machine.

2014 is much more powerful but boots slower than 1985. Why?

The Mess We’re In

His generation of programmers deserve medals for creating so many maintenance programmers (and jobs).

What went wrong?

What do the laws of physics say about computes?

Seven Deadly Sins

code even you cannot udnerstand a week after you wrote it. no comments

code with no specifications

code is shipped as soon as it runs before it is beautiful

code with added features

code that is very very fast very very very obscure and incorrect

code that is not beautiful

code that you wrote without understanding the problem

Legacy code

Programmers who wrote the code are dead

No specs

Written in archaic language which nobady understands

“it works”

Management thinks modifying is easy (hah)

Complexity

Mass of earth

atoms on earth

atoms in universe (big numbers)

So a C program with six 32-bit integers can have more states than the number of atoms on the planet.

What about Javascript? Don’t ask.

A computer is a finite state machine.

State x Event -> New State

Failures - They will fail so you have to deal with it.

Distributed computing

Parallel computing

Concurrent programming

Fault tolerance requires the above.

Systems should self repair.

Languages

In 1985 everybody* knew sh, make, C

Now programmers have no common language.

2500+ languages to choose from.

Efficiency and Clarity

Names

Names are imprecise

Physics

Causality

Simultanuity

Entropy always increases

Speed of Computation

The Ultimate Laptop (is a 1kg black hole)

Physical limits of computation. funny

What can we do?

Entropy reverser (break 2nd law of thermodynamics)

Abolish names and places

URIs are bad

It needs DNS which can be spoofed

Use hashes instead of names hash://e5fa44f2b31c1fb553b6021e7360d07d5d91ff5e

How to find machine; Chord Kademlia sha1(ip)

Combining ideas of git and bittorrent

How to make condenser

Find all identical files

Merge all similar files (How?) (He’s been thinking about this for about 20 years.)

Least compression difference

Summary

We’ve made all this mess

We need to reverse entropy (make things smaller and smaller)

Quantum mechanics set upper limits

We need math

abolish names and places

build the condensor

make low-power computers

Let’s clean up the mess we made.

React RESTful UI Rendering - Pete Hunt

Every new UI at Facebook is done with React.

Used for Mobile UIs too.

Those who cannot remember the past are condemned to repeat it –George Santayana

Past lessons learned:

Evolution of Distributed Systems

Message Passing (MPI)

Message Passing is too low level.

Real application has state that evolves over time.

Distributed Objects (CORBA, RMI, SOAP, DCOM)

too much implicit communication possible

UNPREDICTABLE

When is the computation running?

Where?

OOP impedance mismatch

?
?

multistep, multidirectional messaging -> unpredictable + slow

REST (fixing the problems of distributed object)

performance (throughput, user-perceived performance)

Scalability

Simplicity

Modifiability

Visibility

Reliability

REST constraints (for your success)

Client server

Stateless (no client state on server)

Cacheable

Layered (clients don’t know if you’re hitting the cache server or real server)

Uniform interface (GET, POST)

Evolution of UI Development

Ad-hoc in the beginning; everything jumbled together

MVC

State Change Observation and Events

Order of events can affect the final state you reach (even if they’re the same events)
How do you converge to the same state every time?

React

Virtual DOM

EXPLICIT state transition

shouldComponentUpdate can help a lot

Uniform Interface (React components render() whether it’s first call or Nth call)

Events

Stateless

Cacheability

Layered

(facebook has a new iOS framework)

There are good ideas (CONSTRAINTS) in REST. Try to apply them to your non-web problem.

Q&A

use react-art for canvas/svg/vml

how does react deal with race conditions?

what’s the next frontier in UI dev?

constraint-based layout systems

what is the relationship between react and web components?

why did he say web components aren’t restful?

does facebook use immutable data structures?

yes, they use immutable.js

Typed Clojure in Practice

Converting Clojure to Typed Clojure

Ran a buggy function and let it crash

Now let’s use type checker to find the bug

summarise fn needs to be annotated using ann

next instead of rest

seq instead of first

(t/check-ns)

Typed Clojure is an Optional Type System for Clojure

core.typed

ideas from Typed Racket

Check out Cursive Clojure, because it supports Typed Clojure

http://crossclj.info/ (extracts typed clojure annotations when available)

TypedClojure.vim - mouse over expression gives you type of expression

typed clojure is coming to clojurescript

inference is getting better

Occurrence Typing

HMaps (type for keyword maps)

(HMap :mandatory {:a Num :b Str :c Sym})

’{:a Num :b Str :c Sym}

Multimethods

Polymorphism

Variable-Arity Polymorphism

Datatypes and Protocols

(Is :- part of core.typed?)

Java Interop

CircleCI is a commercial company that uses Typed Clojure

The Future

Call to Action

Annotate your Libraries

If you don’t have your own lib, adopt one and annotate it!

Q&A

When are you going to have dependent types?

Needs to understand it first. Typed racket guys are working on it.

Prismatic Schema?

This has all happened before and it will all happen again - J. M. Barrie - Peter Pan (Mark Allen)

The history of programming languages

Fortran

Lisp

Algol

Cobol

1972 - Jean Sammet - Virtually everyone agrees that today programming is an art, not a science.

Many although fewer contend that programming can and should become a science.

Is programming today more of an art or a science?

first compiler was written in 1952

people didn’t initially believe something like a compiler could be written

the more things change, the more things stay the same.

the goal of early languages were to overcome hardware limitations

1954

Fortran

Dr. Cuthbert Hurd

Fortran Input: Reason Output: Pleasure (funny picture of boardgame)

John Backus

Hated “programming”

Invented “speedcoding”

Lead Fortran Team (1954-57)

Invented BNF (Backus Normal Form)

National Medal of Science (1975)

ACM Turing Award (1977)

(was a fan of APL)

He was happy with how efficient Fortran code generation was

Problems

debugging ahrd

language design was lacking

cost saving and efficiency gains are eaten up by increases in program size and complexity

Lisp

John McCarthy

Invented Lisp in 1959

Also original member of Algol committee

in/then/else

garbage collection

predicted computing utilities (cloud computing) (1961)

Design Goals

enable symbolic reasoning

representation of data and expressions as lists in memory

functional composition and recursion as programming idioms

automatic memory management

Steve Russel coded the first eval function in asm for IBM 704.

McCarthy intented to have a compiler, but eval kind of changed things

Interpreted programs are about 60 times slower

No lexical scope

M-expressions were supposed to replace S-expressions but that never happened

Read “The Humble Programmer” 1972

Algol

1958

1960 revised spec

1968 (Algol68 drama)

Alan Perlis

Peter Naur

Edsger W. Dijkstra

recursion

code blocks with lexical scope

call by value, call by name

intrinsic boolean type

keywords (if/else/for/while)

formally specified grammar

Cobol

portable

english like notation

easy to use

lower the barrier to entry

Grace M Hopper

Introduced records

Conclusions

@bytemeorg

Retaking Rules for Developers

1977

Intelligent systems derive their power from the KNOWLEDGE THEY POSSESS.

How do we manage this knowledge?

Frankly, there were a lot of intellecutally dishonest promises made.

The 2nd AI Winter

Rule authoring is development, whether we call it that or not.

Let’s approach expert systems as code

Complex wiring of function inputs and outputs is complicated.

Can it be done automatically

RULES AS A CONTROL STRUCTURE

unit-of-logic Type[constraints] Type[constraints] => action

Nools (Javascript)

Wongi (Ruby)

Clara (Clojure)

Idris Practical Dependent Types with Practical Examples

Trying to make Dependent Types practical

Iridium window manager

Consistency Without Consensus - Peter Bourgon

1990s Corba

2000s CAP

Partitions and Partitions Tolerance

the system continues to operate despite mesage loss or node failure

Consistency Availability Partitions

CP systems - consistency protocols

Chubby, Doozer - Paxos

ZooKeeper - Zab

Consul, etcd - Raft

? – Viewstamped Replication

They’re slow.

AP systems

Cassandra

Riak

Mongo

Couch

Message Failure

Delayed

Dropped

Out-of-order

Duplicated

CP systems abstract this away

AP systems allow these to happen

but how do you do that without corrupting system state?

CALM Principle - Consistency As Logical Monotonicity

A system should only grow in one direction

ACID 2.0

Associative Commutative Idempotent Distributed, sure, whatever

reuse of ACID acronymn for distributed systems

CRDT

Conflict-free Replicated Data Type

Increment only counter (example)

Sets of User ids for counting { 123, 456 } { 123, 456 } { 123, 456 } Sets are nice, because the union operation is associative, commutative, idempotent

Interlude - Bending the problem

CRDTs in Production - Event Streams

Event timestamp, actor, verb, thing

fan out on write (every user gets an inbox)

can use a lot of space

fan in on read (every producer has an outbox)

uses less space

the downside is the read becomes more expensive

Roshi Set (new kind of set from soundcloud)

Reading is easy

Writing is interesting

S+ { A/1 B/2 } # add set S- { C/3 D/6 } # delete set

Making it real

Redis has all the primitives necessary

Consistency without consensus = CRDT

Embrace Invariants

Maybe bend your problem, not your solution

Building Realtime Analytics Systems

Finding a solution

(Initially you might think…) Load all your data into Hadoop. Query it. Done

MapReduce/Hadoop has problems. It can be slow.

Not optimized for query latency

Need to introduce a query layer to make queries faster.

Making Queries Faster

What types of queries to optimize for?

Intially just Hadoop

Then Hadoop for preprocessing and storage -> Various data stores

Existing data stores were not good enough, so they made their own called Druid.

Druid is optimized for reads

Druid is a column store

Kafka (Loading?) (It’s a message queue of some sort)

Storm (Processing)

arch

Kafka Brokers -> Strom Workers -> Druid Realtime Workers -> Druid Historical Cluster \ / Druid Query Broker

What we gained

No need for hadoop

Faster

What we gave up

Difficult to handle corections of existing data

Windows may be too small for fully accurate operations

Hadoop was actually good at these things

Hadoop might be brought back to rectify this.

What this might look like

Storm Kafka Druid Hadoop

Glue to connect these pieces together

storm-kafka Camus Tranquility Druid already knows how to talk to Hadoop

Scheme in the Morning - Programming Should Eat Itself - Nada Amin

Why?

Why not?

“It made my head hurt.” –Dan Friedman

Controlling Time and Space - Evan Czaplicki

Undertanding the many formulations of Functional Reactive Programming

He designed Elm

First Order FRP - How it works in Elm

Signal Graphs

Input: Explicit structure for event handling Transform: Raw input gets transformed with lift: “`lift : (a -> b) -> Signal a -> Signal b“` State: “`foldp : (a -> b -> b) -> b -> Signal a -> Signal b“` Merge: “` merge : Signal a -> Signal a -> Signal a

Core Design

Signals are connected to the world

Signals are infinite - There’s no such thing as deleting a signal

Signal graphs are static - There’s a known structure

Synchronous by default

Benefits of Elm

Efficiency - event comes from world, flows through graph, world is changed

Architecture - elm apps have 4 parts - same general structure

Hot-swapping - can change code and have it reflected right away

Time-travel Debugger - go back and forth between states

Higher Order FRP (alternative to core design)

What if signal graphs were dynamic?

“` join : Signal (Signal a) -> Signal a “`

Problem

creating a new signal may need infinite look back - memory growth llnear with time

Solution

restrict the definition of join with fancier types

Higher-order functional reactive programming in bounded space

However

hot swapping not possible

time travel not easy

Would he use this feature even if he had it? What are the pros of dynamic signal graphs?

Asynchronous Data Flow

The only core design thing is left is that signals are connected to the world

Arrowized FRP

Haskell: Yampa, Netwire

Elm: Automaton

Design

Signals are not connected to world

Signals graphs are again not static

Dynamic Collections

Cons

No way to talk about signals;

Understand

Categorize

Is it sync by default?

Does it allow async?

Can I talk about inputs?

Allows graph reconfig?

Evaluate

What properties do I need for my application?

What is debugging like?

Does the code come out nice?

PureScript

because javascript is a mess

Future Ad Labs implemented captchas as little games (in straight js + jquery)

Ideally, the game engine would be:

Functional

Reactive

Support Animations

Elm is like a user-friendly Haskell

Constraints!

deliverable size

unpredictable environment (ie?)

Tried TypeScript first

TypeScript

rxjs/baconjs

html canvas

PureScript (currently impleented in Haskell)

Looks like Haskell, but generates fairly light JS.

Runtime is fairly light

haskelly syntax

close to js

actually pure

has side effects system & ffi

Transducers

What are they?

extract the essence of map, filter et al

away from the functions that transform seqs/collections

so they can be used elsewhere

recasting them as process transformations

What kind of processes?

ones that can be defined in terms of a succession of steps

where each step ingests an input

building a collection is just one instance

seeded left reduce is the generalization

Why ‘transducer’

reduce

‘lead back’

ingest

‘carry into’

transduce

‘lead across’

on the way back/in, will carry inputs across a series of transformations

Transducers in the Real World

put baggage on plane

as you do that

break apart pallets remove bags that smell like food label heavy bags

Conveyances, sources, sinks are irrelevant

and unspecified

rules don’t care (where something comes from)

Transformation in the Programming World

(comp (partial map label-heavy) (partial filter non-food?) (partial mapcat unbundle-pallet))

No re-use

Every new collection/process defines its own versions of map, filter, mapcat et all

Composed algorithms are needlessly slow

Using Transducers

they can be used with many different types

Transducible Processes

into, sequence, transduce, chan etc that accept transducers

use the transducer to transform their (internal, encapsulated) reducing function

do their job with the transformed reducing function

Deriving Transducers

Lectures on Constructive Functional Programming by R. S. Bird

Many list fns can be defined in terms of foldr

Similarly, you can define them in terms of foldl (aka reduce)

The problem with regular map/filter/mapcat fns is that they have conj in them

That complects these functions with sequences

Transducers are fully decoupled

Know nothing of process they modify

May call step 0, 1 or more times

Must pass previous result as next r otherwise must know nohting of r

Backwards comp?

Transducers are fast

No interim collections

Transducer Types, Thus Far

Early Termination

Reduced

Clojure’s reduce supports early termination via reduced

Transducers must support reduced

Reducing processes must also support reduced

State

Some transducers require state

example: take, partition

Completion

Some processes complete

Might want to do a final transformation at end of input

Completion Operation

Init

Spreadsheets for developers - Felienne Hermans

Spreadsheets are code. (people think that spreadsheets are just data)

Formulas are turing complete

Suffers from same problems as code

You should learn spreadsheets next

Live Coding

Pure Functional

Lingua Franca of computing (everyone else is doing it except programmers)

Selection Sort

There’s a notation for naming things.

Cap’n Proto and Rust - Type Systems for Sharing - David Renshaw

Sandstorm was the project that was the motivation for Cap’n Proto

All communication in sandstorm must go through capn proto

What is Cap’n Proto?

is a type system for fast, robust, secure, multi-language distributed computing

Will be using Rust language to demonstrate Cap’n Proto.

Eight Fallacies of Distributed Computing

First heard of these 8 fallacies during Java One in 1994ish?

Fallacy: a wrong belief, a false or mistaken idea

Most of his statements are going to be false

The Network is Reliable

Latency is Zero

It’s not just about the speed of light; it’s about what the other node is doing; could be busy garbage collecting

Bandwidth is Infinite

Bandwidth is data over time

The Network is Secure

Topology Doesn’t Change

There is One Administrator

Transport Cost is Zero

The Network is Homogenous

In the real world

Corba and RMI are dead or almost dead

Anything that hides the network from you hides the fallacies from you

Web Sockets, Polling

Timeouts - good, bad and ugly

Trust Physics

Read the docs and TEST if the docs are true

Are you real time?

go back and watch the Jepsen II Talk

Let’s be careful out there.

Clojure in Unity 3D: Functional Video Game

Game Development is Hard

Game Development Sucks

Clojure + Unity

this is pre-alpha software

Demos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment