The Ideas of Clojure - Things I learn from Clojure
-
Upload
hsuan-fu-lien -
Category
Technology
-
view
1.179 -
download
5
Transcript of The Ideas of Clojure - Things I learn from Clojure
About me@randylien
UI Engineer
#WebAppsRocks
#JavaScriptIsNotSoJavaScript
#WhenIsNextReactJS.TwMeetup
#clojurians.tw@facebook
Tapestry Dude - https://goo.gl/R5m3am (CC BY-SA 2.0)
The Creator of ClojureRich Hickey
"Hickey is the new Messiah of software development. Watch and listen to his talks, and you will understand."
– http://bepsays.com/2014/07/08/how-rich-is-rich-hickey/
Philosophy
Focus
Simplicity
Empowerment
Pure functions
Expressive Practical
ClarityConsistency
Separation of
concernsConcise
Direct Interop
- The Joy of Clojure
Philosophy - Focus
• Syntax will not bother you
• Consistency
• Dynamic System
• Almost everything defined in Clojure can be redefined (Even while program is running)
• Use Macro you can build anything you want to do
Philosophy - Empowerment
• Use Java Virtual Machine
• Java is mature and has many libraries
• JavaScript is everywhere (ClojureScript)
Data Types
• Integers - 123
• Doubles - 1.23
• Ratios - 1/23
• Strings - "JCConf"
• "Double Quotes Only"
• Characters - \J \C
Data Types (cont.)
• Symbols - bar
• Keywords - :foo
• Booleans - true false
• Null - nil
• Regex - #"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+"
Data Structure• Lists - (1 2 3)
• Prepend
• Vectors - [1 2 3]
• Zero indexed. Append
• Maps - {:a 1, :b 2, :c "3"}
• Key-value pair
• Comma will be ignored
• Sets - #{1 2 3}
• Unique. Unordered
functions & composition
• map, reduce, filter
• partial, comp
• iterate
• repeat, repeatedly
• Many built-in functions and you don’t need to create. Just compose it!
Why immutable?
• No resource limitation
• Persistent data structure
• Record - Share the same data
• Key to do functional programming
• No side effect
• atom is mutable
REPL ?
• Read–Eval–Print Loop
• nREPL (network REPL)
• Good for doing TDD
• clojure.test
• ClojureScript - Browser can connect to nREPL
Summary
• Clojure is a practical functional programming language
• Java and JavaScript are two major languages and Clojure and ClojureScript can run on them
• Using REPL in your TDD practices would be helpful
• Pure functions and Immutable data structure can make your system stable and easy to reason about
Summary (cont.)
• Clojure has much better tooling and keep improving it
• ClojureScript is hotter than Clojure!
• Many companies are using Clojure
• booking.com, Yahoo, Puppet, Walmart, twitter, heroku, nubank…etc
• STM, transducer, core.asyn
If you want to know more…
• Living Clojure
• The Joy of Clojure
• ClojureScript Unraveled
• Clojure Applied
• Clojure for the Brave and True
Online resource
• http://www.tryclj.com/
• http://www.4clojure.com/
Worth to watch
• Simple Made Easy
• Clojure Made Simple
• The Value of Values
• The Language of the System