0
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 co...
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   ○ Effic...
Designed for Concurrency● Machines are not getting faster, they just  have more cores.● Shared access to mutable state mak...
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 in...
ComplexitySimpleComplex
How I/we made things complex● Teamwork● Robots  ○ Explore unknown maze  ○ Detect barcodes --> action  ○ Travel over seesaw...
ComplexitySimple                Easy
ComplexityComplex                HardSimple                 Easy
ComplexityObjective                             SubjectiveComplex                                  Hard      "Elegance and...
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● Decomp...
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 co...
Thinking with data● data is simple● Why wrap it in classes"It is better to have 100 functions operate on one datastructure...
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...
Identity/state/value model● Object Oriented Approach                                   Memory                             ...
Identity/state/value model● Object Oriented Approach● Problems  ○ Stable value  ○ history (snapshot)  ○ Concurrent modific...
Stable value● Spaceship  ○ position    ■ x,y    ■ Position object  ○ velocity    ■ MovementState
Stable value● Spaceship  ○ position    ■ x,y    ■ Position object  ○ velocity    ■ MovementState  ○ ...  ○ Consistent and ...
Stable value● Spaceship  ○ position    ■ x,y    ■ Position object  ○ velocity    ■ MovementState  ○ ...  ○ Consistent and ...
Stable value● Creating the object● Not consistent
Identity/state/value model● Object Oriented Approach● Problems  ○ Stable value  ○ history (snapshot)  ○ Concurrent modific...
Snapshot & history● Take a picture● Look later at it again.
Identity/state/value model● Object Oriented Approach● Problems  ○ Stable value  ○ history (snapshot)  ○ Concurrent modific...
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,●...
Identity/state/value model● OOP  ○ complects state and identity● Clojure  ○ Separation value / state / identity  ○ Percept...
Clojure reference model                                 Value                         :name Heart Of Gold                 ...
Clojure reference model                                 Value                         :name Heart Of Gold                 ...
Clojure reference model                                 Value                         :name Heart Of Gold                 ...
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 ea...
Why Clojure?  ?
Upcoming SlideShare
Loading in...5
×

Why clojure

1,657

Published on

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/

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,657
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Why clojure"

  1. 1. Why Clojure?
  2. 2. Why Clojure? Why was it created?What do we mean with complexity?How does clojure makes things more simple?
  3. 3. When was Clojure● 2007: introduction by Rich Hickey● 2009: version 1.0 ....● 2013: version 1.5
  4. 4. What is Clojure● A Lisp● for Functional Programming● Running on the JVM, CLR and browsers● Designed for concurrency
  5. 5. A LispMany concepts of Lisps are taken over by otherlanguages:● Conditionals● First-class functions● Recursion● Garbage collection● Programs made up out of expressions
  6. 6. Functional Programming● Provides a way out of the multi-core conundrum● Makes programs simpler by decomplecting them.
  7. 7. 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.
  8. 8. 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.
  9. 9. Why is Clojure● Reducing complexity● to be easy? not exactly...
  10. 10. What do we mean with● Complex● Simple● Hard● Easy
  11. 11. Complexity ComplexConsisting of many different and connected parts. To Complect be interwoven or interconnected
  12. 12. ComplexitySimpleComplex
  13. 13. How I/we made things complex● Teamwork● Robots ○ Explore unknown maze ○ Detect barcodes --> action ○ Travel over seesaw● How to test? ○ We couldnt● Unmanageable complexity
  14. 14. ComplexitySimple Easy
  15. 15. ComplexityComplex HardSimple Easy
  16. 16. ComplexityObjective SubjectiveComplex Hard "Elegance and familiarity are orthogonal." — Rich Hickey Simple Easy
  17. 17. Types of Complexity● Essential Complexity● Accidental Complexity
  18. 18. Examples of complexity● State● Inheritance● Objects ○ state ○ identity ○ value● Memory management● Variables
  19. 19. Why does simple matter?● Formal reasoning ○ can be hard● Extendability ○ Composing● Testability ○ isolation
  20. 20. How is Clojure simple(r)● Functional Programming ○ Pure functions● Immutable data structures● Thinking with data● Decomplecting state / value / identity
  21. 21. Immutability● Numbers are immutable in your language● If you use Java, Strings are immutable● Imagine if theyre not!
  22. 22. 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
  23. 23. 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
  24. 24. Thinking with data● data is simple● Clojure map
  25. 25. 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)
  26. 26. Identity/state/value model● Object Oriented Approach Memory SpaceShipship1 - name -x -y - velocity
  27. 27. Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  28. 28. Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState
  29. 29. Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState ○ ... ○ Consistent and stable object!
  30. 30. Stable value● Spaceship ○ position ■ x,y ■ Position object ○ velocity ■ MovementState ○ ... ○ Consistent and stable object! NO!
  31. 31. Stable value● Creating the object● Not consistent
  32. 32. Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  33. 33. Snapshot & history● Take a picture● Look later at it again.
  34. 34. Identity/state/value model● Object Oriented Approach● Problems ○ Stable value ○ history (snapshot) ○ Concurrent modification
  35. 35. Concurrent modification● Guarantee consistency?● Stop the world!
  36. 36. Clojure approach● Remove ambiguity of definitions ○ value ○ state ○ identity
  37. 37. 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
  38. 38. Identity/state/value model● OOP ○ complects state and identity● Clojure ○ Separation value / state / identity ○ Perception becomes possible ○ Consistency management trivial
  39. 39. Clojure reference model Value :name Heart Of Gold :position (0,0) :velocity 100 km/s Refship1
  40. 40. 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
  41. 41. 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
  42. 42. Clojure reference model● Perception without stopping the world● Atomic updates ○ Transactions
  43. 43. Why Clojure? SimplicityExpressiveness Concurrency
  44. 44. 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
  45. 45. Why Clojure? ?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×