Slide 1

Slide 1 text

THE IDEAS OF CLOJURE JCConf 2015/12/04 Randy Lien Things I learn from Clojure

Slide 2

Slide 2 text

About me @randylien UI Engineer #WebAppsRocks #JavaScriptIsNotSoJavaScript #WhenIsNextReactJS.TwMeetup #clojurians.tw@facebook

Slide 3

Slide 3 text

Survey! • Heard Clojure? • Clojure developer? • Enjoy Java development?

Slide 4

Slide 4 text

“I don’t know Java.” – Speaker

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

History of programming languages

Slide 7

Slide 7 text

LISP

Slide 8

Slide 8 text

Clojure ?

Slide 9

Slide 9 text

React.js Conf 2015

Slide 10

Slide 10 text

Tapestry Dude - https://goo.gl/R5m3am (CC BY-SA 2.0) The Creator of Clojure
 Rich Hickey

Slide 11

Slide 11 text

"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/

Slide 12

Slide 12 text

Few ideas I want to share

Slide 13

Slide 13 text

Philosophy

Slide 14

Slide 14 text

Philosophy Focus Simplicity Empowerment Pure functions Expressive Practical Clarity
 Consistency Separation 
 of 
 concerns Concise Direct Interop - The Joy of Clojure

Slide 15

Slide 15 text

Philosophy - Simplicity • Pure functions • Immutable • Simple abstractions • defprotocol • deftype

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Philosophy - Empowerment • Use Java Virtual Machine • Java is mature and has many libraries • JavaScript is everywhere (ClojureScript)

Slide 18

Slide 18 text

Consistency

Slide 19

Slide 19 text

Syntax does matter

Slide 20

Slide 20 text

Java + Python + JavaScript ?

Slide 21

Slide 21 text

JaPythonScript?

Slide 22

Slide 22 text

Data Types • Integers - 123 • Doubles - 1.23 • Ratios - 1/23 • Strings - "JCConf" • "Double Quotes Only" • Characters - \J \C

Slide 23

Slide 23 text

Data Types (cont.) • Symbols - bar • Keywords - :foo • Booleans - true false • Null - nil • Regex - #"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]+"

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

function definition

Slide 26

Slide 26 text

function definition doc string

Slide 27

Slide 27 text

Clojure • (+ 1 2) • (+ 1 2 3) • (into [] 2) General • 1 + 2 • 1 + 2 + 3 • [].push(2)

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Use host libraries - Java

Slide 30

Slide 30 text

Use host libraries - JavaScript

Slide 31

Slide 31 text

DEMO

Slide 32

Slide 32 text

functions & composition

Slide 33

Slide 33 text

functions & composition • map, reduce, filter • partial, comp • iterate • repeat, repeatedly • Many built-in functions and you don’t need to create.
 Just compose it!

Slide 34

Slide 34 text

DEMO

Slide 35

Slide 35 text

Values

Slide 36

Slide 36 text

Values should be… • Value! • operated by functions • time-relative • Immutable

Slide 37

Slide 37 text

Why Immutable?

Slide 38

Slide 38 text

Why mutable?

Slide 39

Slide 39 text

Why mutable? • Limitations of early computers: Small RAM and disk • New information replaces old

Slide 40

Slide 40 text

Why immutable? • No resource limitation • Persistent data structure • Record - Share the same data • Key to do functional programming • No side effect • atom is mutable

Slide 41

Slide 41 text

REPL Driven Development

Slide 42

Slide 42 text

REPL ? • Read–Eval–Print Loop • nREPL (network REPL) • Good for doing TDD • clojure.test • ClojureScript - Browser can connect to nREPL

Slide 43

Slide 43 text

REPL DEMO - ClojureScript

Slide 44

Slide 44 text

REPL DEMO - Clojure

Slide 45

Slide 45 text

Tooling Eco-system

Slide 46

Slide 46 text

Clojars emacs LightTable

Slide 47

Slide 47 text

Leiningen

Slide 48

Slide 48 text

Summary

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

If you want to know more… • Living Clojure • The Joy of Clojure • ClojureScript Unraveled • Clojure Applied • Clojure for the Brave and True

Slide 52

Slide 52 text

Online resource • http://www.tryclj.com/ • http://www.4clojure.com/

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

Worth to watch • Simple Made Easy • Clojure Made Simple • The Value of Values • The Language of the System

Slide 55

Slide 55 text

Thanks