Why clojure
Upcoming SlideShare
Loading in...5
×
 

Why clojure

on

  • 2,010 views

Talk on why clojure was created. This talk was given at the first belgian clojure meetup 27th of march 2013 in mechelen. ...

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/

Statistics

Views

Total Views
2,010
Views on SlideShare
1,392
Embed Views
618

Actions

Likes
5
Downloads
11
Comments
0

2 Embeds 618

http://tgoossens.wordpress.com 430
https://twitter.com 188

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Why clojure Why clojure Presentation Transcript

  • Why Clojure?
  • Why Clojure? Why was it created?What do we mean with complexity?How does clojure makes things more simple?
  • When was Clojure● 2007: introduction by Rich Hickey● 2009: version 1.0 ....● 2013: version 1.5
  • What is Clojure● A Lisp● for Functional Programming● Running on the JVM, CLR and browsers● Designed for concurrency
  • A LispMany concepts of Lisps are taken over by otherlanguages:● Conditionals● First-class functions● Recursion● Garbage collection● Programs made up out of expressions
  • Functional Programming● Provides a way out of the multi-core conundrum● Makes programs simpler by decomplecting them.
  • Running on the JVM, CLR, browser● JVM / CLR have huge benefits: ○ Libraries ○ Memory and resource management ○ Efficient and robust● JavaScript has a huge reach: ○ Its the most widely deployed language ○ Through ClojureScript, we can target everywhere JavaScript runs.● Clojure is symbiotic with its host platform.
  • 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.
  • Why is Clojure● Reducing complexity● to be easy? not exactly...
  • What do we mean with● Complex● Simple● Hard● Easy
  • Complexity ComplexConsisting of many different and connected parts. To Complect be interwoven or interconnected
  • ComplexitySimpleComplex
  • How I/we made things complex● Teamwork● Robots ○ Explore unknown maze ○ Detect barcodes --> action ○ Travel over seesaw● How to test? ○ We couldnt● Unmanageable complexity
  • ComplexitySimple Easy
  • ComplexityComplex HardSimple Easy
  • ComplexityObjective SubjectiveComplex Hard "Elegance and familiarity are orthogonal." — Rich Hickey Simple Easy
  • Types of Complexity● Essential Complexity● Accidental Complexity
  • Examples of complexity● State● Inheritance● Objects ○ state ○ identity ○ value● Memory management● Variables
  • Why does simple matter?● Formal reasoning ○ can be hard● Extendability ○ Composing● Testability ○ isolation
  • How is Clojure simple(r)● Functional Programming ○ Pure functions● Immutable data structures● Thinking with data● Decomplecting state / value / identity
  • Immutability● Numbers are immutable in your language● If you use Java, Strings are immutable● Imagine if theyre not!
  • Immutable building blocks● Primitives: numbers, strings● Collections: lists, vectors, strings, maps, sets● "Changing" a collection creates an (efficient) copy. (think: Git)● Dont worry about state
  • Thinking with data● data is simple● Why wrap it in classes"It is better to have 100 functions operate on one datastructure than 10 functions on 10 data structures." — Alan Perlis
  • Thinking with data● data is simple● Clojure map
  • 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)
  • Identity/state/value model● Object Oriented Approach Memory SpaceShipship1 - name -x -y - velocity
  • Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  • Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState
  • Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState ○ ... ○ Consistent and stable object!
  • Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState ○ ... ○ Consistent and stable object! NO!
  • Stable value● Creating the object● Not consistent
  • Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  • Snapshot & history● Take a picture● Look later at it again.
  • Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  • Concurrent modification● Guarantee consistency?● Stop the world!
  • Clojure approach● Remove ambiguity of definitions ○ value ○ state ○ identity
  • 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
  • Identity/state/value model● OOP ○ complects state and identity● Clojure ○ Separation value / state / identity ○ Perception becomes possible ○ Consistency management trivial
  • Clojure reference model Value :name Heart Of Gold :position (0,0) :velocity 100 km/s Refship1
  • Clojure reference model Value :name Heart Of Gold :position (0,0) :velocity 100 km/s Refship1 Value :name Heart Of Gold :position (100,100) :velocity 100 km/s
  • Clojure reference model Value :name Heart Of Gold :position (0,0) :velocity 100 km/s Refship1 Value :name Heart Of Gold :position (100,100) :velocity 100 km/s
  • Clojure reference model● Perception without stopping the world● Atomic updates ○ Transactions
  • Why Clojure? SimplicityExpressiveness Concurrency
  • Why Clojure? Are we there yet?http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey Simple made easy http://www.infoq.com/presentations/Simple-Made-Easy Out of The Tarpit http://shaffner.us/cs/papers/tarpit.pdf
  • Why Clojure? ?