The Ideas of Clojure - Things I learn from Clojure

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

Embed Size (px)

Transcript of The Ideas of Clojure - Things I learn from Clojure


    JCConf 2015/12/04

    Randy Lien

    Things I learn from Clojure

  • About [email protected]

    UI Engineer




    #[email protected]

  • Survey!

    Heard Clojure?

    Clojure developer?

    Enjoy Java development?

  • I dont know Java.


  • History of programming languages

  • LISP

  • Clojure ?

  • React.js Conf 2015

  • Tapestry Dude - (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."

  • Few ideas I want to share

  • Philosophy

  • Philosophy




    Pure functions

    Expressive Practical


    Separation of


    Direct Interop

    - The Joy of Clojure

  • Philosophy - Simplicity

    Pure functions


    Simple abstractions



  • Philosophy - Focus

    Syntax will not bother you


    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)

  • Consistency

  • Syntax does matter

  • Java + Python + JavaScript ?

  • JaPythonScript?

  • 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._%+-][email protected][A-Z0-9.-]+\.[A-Z]+"

  • Data Structure Lists - (1 2 3)


    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

  • function definition

  • function definition

    doc string

  • Clojure

    (+ 1 2)

    (+ 1 2 3)

    (into [] 2)


    1 + 2

    1 + 2 + 3


  • Use host libraries - Java

  • Use host libraries - JavaScript

  • DEMO

  • functions & composition

  • functions & composition

    map, reduce, filter

    partial, comp


    repeat, repeatedly

    Many built-in functions and you dont need to create. Just compose it!

  • DEMO

  • Values

  • Values should be


    operated by functions



  • Why Immutable?

  • Why mutable?

  • Why mutable?

    Limitations of early computers: Small RAM and disk

    New information replaces old

  • 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 Driven Development

  • REPL ?

    ReadEvalPrint Loop

    nREPL (network REPL)

    Good for doing TDD


    ClojureScript - Browser can connect to nREPL

  • REPL

    DEMO - ClojureScript

  • REPL

    DEMO - Clojure

  • Tooling Eco-system

  • Clojars



  • Leiningen

  • Summary

  • 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, Yahoo, Puppet, Walmart, twitter, heroku, nubanketc

    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

  • Worth to watch

    Simple Made Easy

    Clojure Made Simple

    The Value of Values

    The Language of the System

  • Thanks