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

  • THE IDEAS OF CLOJURE

    JCConf 2015/12/04

    Randy Lien

    Things I learn from Clojure

  • About [email protected]

    UI Engineer

    #WebAppsRocks

    #JavaScriptIsNotSoJavaScript

    #WhenIsNextReactJS.TwMeetup

    #[email protected]

    http://clojurians.tw

  • Survey!

    Heard Clojure?

    Clojure developer?

    Enjoy Java development?

  • I dont know Java.

    Speaker

  • History of programming languages

    https://en.wikipedia.org/wiki/History_of_programming_languages

  • LISP

  • Clojure ?

  • React.js Conf 2015

  • Tapestry Dude - https://goo.gl/R5m3am (CC BY-SA 2.0)

    The Creator of ClojureRich Hickey

    https://goo.gl/R5m3am

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

  • Few ideas I want to share

  • Philosophy

  • Philosophy

    Focus

    Simplicity

    Empowerment

    Pure functions

    Expressive Practical

    ClarityConsistency

    Separation of

    concernsConcise

    Direct Interop

    - The Joy of Clojure

  • Philosophy - Simplicity

    Pure functions

    Immutable

    Simple abstractions

    defprotocol

    deftype

  • 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)

  • 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)

    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

  • function definition

  • function definition

    doc string

  • Clojure

    (+ 1 2)

    (+ 1 2 3)

    (into [] 2)

    General

    1 + 2

    1 + 2 + 3

    [].push(2)

  • Use host libraries - Java

  • Use host libraries - JavaScript

  • DEMO

  • functions & composition

  • functions & composition

    map, reduce, filter

    partial, comp

    iterate

    repeat, repeatedly

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

  • DEMO

  • Values

  • Values should be

    Value!

    operated by functions

    time-relative

    Immutable

  • 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

    clojure.test

    ClojureScript - Browser can connect to nREPL

  • REPL

    DEMO - ClojureScript

  • REPL

    DEMO - Clojure

  • Tooling Eco-system

  • Clojars

    emacs

    LightTable

  • 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

    booking.com, Yahoo, Puppet, Walmart, twitter, heroku, nubanketc

    STM, transducer, core.asyn

    http://booking.com

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

    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

    http://www.infoq.com/presentations/Simple-Made-Easyhttps://www.youtube.com/watch?v=VSdnJDO-xdghttps://www.youtube.com/watch?v=-6BsiVyC1kMhttps://www.youtube.com/watch?v=ROor6_NGIWU

  • Thanks