why clojure

45
Why Clojure?

Upload: thomas-goossens

Post on 06-May-2015

1.634 views

Category:

Technology


4 download

DESCRIPTION

Talk on why clojure was created. This talk was given at the first belgian clojure meetup 27th of march 2013 in mechelen. Read the debriefing of this meetup: https://tgoossens.wordpress.com/2013/04/04/first-belgian-clojure-meetup-debriefing/

TRANSCRIPT

Page 1: Why clojure

Why Clojure?

Page 2: Why clojure

Why Clojure?

Why was it created?

What do we mean with complexity?

How does clojure makes things more simple?

Page 3: Why clojure

When was Clojure

● 2007: introduction by Rich Hickey

● 2009: version 1.0

....

● 2013: version 1.5

Page 4: Why clojure

What is Clojure

● A Lisp

● for Functional Programming

● Running on the JVM, CLR and browsers

● Designed for concurrency

Page 5: Why clojure

A Lisp

Many concepts of Lisps are taken over by other languages:● Conditionals● First-class functions● Recursion● Garbage collection● Programs made up out of expressions

Page 6: Why clojure

Functional Programming

● Provides a way out of the multi-core conundrum

● Makes programs simpler by decomplecting them.

Page 7: Why clojure

Running on the JVM, CLR, browser

● JVM / CLR have huge benefits:○ Libraries○ Memory and resource management○ Efficient and robust

● JavaScript has a huge reach:○ It's the most widely deployed language○ Through ClojureScript, we can target everywhere

JavaScript runs.● Clojure is symbiotic with its host platform.

Page 8: Why clojure

Designed for Concurrency

● Machines are not getting faster, they just have more cores.

● Shared access to mutable state makes multi-core programming a nightmare.

● Immutability makes many of the problems go away.

● Separating identity and state can solve all the other problems.

Page 9: Why clojure

Why is Clojure

● Reducing complexity

● to be easy? not exactly...

Page 10: Why clojure

What do we mean with

● Complex

● Simple

● Hard

● Easy

Page 11: Why clojure

Complexity

To Complectbe interwoven or interconnected

Complex

Consisting of many different and connected parts.

Page 12: Why clojure

Complexity

Complex

Simple

Page 13: Why clojure

How I/we made things complex

● Teamwork ● Robots

○ Explore unknown maze

○ Detect barcodes --> action

○ Travel over seesaw

● How to test?○ We couldn't

● Unmanageable complexity

Page 14: Why clojure

Complexity

Simple Easy

Page 15: Why clojure

Complexity

HardComplex

Simple Easy

Page 16: Why clojure

HardComplex

Simple Easy

ComplexityObjective Subjective

"Elegance and familiarity are orthogonal." — Rich Hickey

Page 17: Why clojure

Types of Complexity

● Essential Complexity

● Accidental Complexity

Page 18: Why clojure

Examples of complexity

● State

● Inheritance

● Objects ○ state○ identity○ value

● Memory management● Variables

Page 19: Why clojure

Why does simple matter?

● Formal reasoning○ can be hard

● Extendability○ Composing

● Testability○ isolation

Page 20: Why clojure

How is Clojure simple(r)

● Functional Programming○ Pure functions

● Immutable data structures

● Thinking with data

● Decomplecting state / value / identity

Page 21: Why clojure

Immutability

● Numbers are immutable in your language

● If you use Java, Strings are immutable

● Imagine if they're not!

Page 22: Why clojure

Immutable building blocks

● Primitives: numbers, strings

● Collections: lists, vectors, strings, maps, sets

● "Changing" a collection creates an (efficient) copy. (think: Git)

● Don't worry about state

Page 23: Why clojure

Thinking with data

● data is simple

● Why wrap it in classes

"It is better to have 100 functions operate on one data structure than 10 functions on 10 data structures." — Alan Perlis

Page 24: Why clojure

Thinking with data

● data is simple

● Clojure map

Page 25: Why clojure

Thinking with data

; Get the first name(get-in person [:name :first-name])

; Get all birth dates from a list of persons.(map :birthdate people)

Page 26: Why clojure

Identity/state/value model

● Object Oriented Approach

SpaceShip

- name- x- y- velocity

ship1

Memory

Page 27: Why clojure

● Object Oriented Approach

● Problems○ Stable value

○ history (snapshot)

○ Concurrent modification

Identity/state/value model

Page 28: Why clojure

● Spaceship○ position

■ x,y■ Position object

○ velocity■ MovementState

Stable value

Page 29: Why clojure

● Spaceship○ position

■ x,y■ Position object

○ velocity■ MovementState

○ ...

○ Consistent and stable object!

Stable value

Page 30: Why clojure

● Spaceship○ position

■ x,y■ Position object

○ velocity■ MovementState

○ ...

○ Consistent and stable object! NO!

Stable value

Page 31: Why clojure

Stable value

● Creating the object

● Not consistent

Page 32: Why clojure

● Object Oriented Approach

● Problems○ Stable value

○ history (snapshot)

○ Concurrent modification

Identity/state/value model

Page 33: Why clojure

Snapshot & history

● Take a picture

● Look later at it again.

Page 34: Why clojure

● Object Oriented Approach

● Problems○ Stable value

○ history (snapshot)

○ Concurrent modification

Identity/state/value model

Page 35: Why clojure

Concurrent modification

● Guarantee consistency?

● Stop the world!

Page 36: Why clojure

Clojure approach

● Remove ambiguity of definitions○ value○ state○ identity

Page 37: Why clojure

Identity/state/value model

● Value○ fixed: 42 , "answer"

● Identity○ series of different values over time

Me, a car,

● State○ Value of an identity at a certain point in time

Page 38: Why clojure

Identity/state/value model

● OOP○ complects state and identity

● Clojure○ Separation value / state / identity

○ Perception becomes possible

○ Consistency management trivial

Page 39: Why clojure

Clojure reference model

:name Heart Of Gold:position (0,0) :velocity 100 km/s

ship1

Value

Ref

Page 40: Why clojure

Clojure reference model

:name Heart Of Gold:position (0,0) :velocity 100 km/s

ship1

Value

Ref

:name Heart Of Gold:position (100,100):velocity 100 km/s

Value

Page 41: Why clojure

Clojure reference model

:name Heart Of Gold:position (0,0) :velocity 100 km/s

ship1

Value

Ref

:name Heart Of Gold:position (100,100) :velocity 100 km/s

Value

Page 42: Why clojure

Clojure reference model

● Perception without stopping the world

● Atomic updates○ Transactions

Page 43: Why clojure

Why Clojure?

Simplicity

Expressiveness

Concurrency

Page 44: Why clojure

Why Clojure?Are we there yet?

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey

Simple made easyhttp://www.infoq.com/presentations/Simple-Made-Easy

Out of The Tarpithttp://shaffner.us/cs/papers/tarpit.pdf

Page 45: Why clojure

Why Clojure?

?