Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clojure is ⚡️Awesome⚡️

Avi Flax
August 22, 2017

Clojure is ⚡️Awesome⚡️

Designed to introduce experienced programmers to Clojure and hopefully pique their interest.

Avi Flax

August 22, 2017
Tweet

More Decks by Avi Flax

Other Decks in Programming

Transcript

  1. * What: An Open Source programming system * Who: Initial

    design and implementation by Rich Hickey, BDFL. * When: First preview release: 2007; 1.0 was in 2009. Some W’s What Who When by Avi Flax • avi@aviflax.com • August 2017
  2. * Why does it exist? * Hickey did a lot

    of work with C# and Java and was dissatisfied * He wanted a LISP that: * fast, pragmatic * embraces immutability, concurrency, and polymorphism * not constrained by backwards compatibility * empowered and accelerated by building on an established platform Why by Avi Flax • avi@aviflax.com • August 2017
  3. * This is a lot of stuff, and itʼs not

    even everything. * But I think itʼs actually more than the sum of its parts. * I think Clojure is… In a ! ⚡ ⚡ by Avi Flax • avi@aviflax.com • August 2017
  4. * Each of these aspects of Clojure is excellent, but

    itʼs how they fit together to enable and empower designing and building great software over time that is really ⚡Awesome⚡! * We'll revisit each of these strengths later; next I'd like to show you some examples. A cohesive toolkit for thinking & building over time by Avi Flax • avi@aviflax.com • August 2017
  5. API and database are written in Clojure by Avi Flax

    • avi@aviflax.com • August 2017
  6. * API and UI are written in Clojure and ClojureScript

    * Other companies using Clojure include Walmart, Chartbeat, Consumer Reports, Puppet, Beanstalk, The Climate Corporation, Thoughtworks, Cerner, Atlassian, and many more by Avi Flax • avi@aviflax.com • August 2017
  7. * Donʼt want to dwell on this; just want you

    to be able to read the examples. * The syntax definitely looks strange at first, but: * People generally get used to the syntax very quickly and just stop noticing it. <interlude> Syntax by Avi Flax • avi@aviflax.com • August 2017
  8. * Referential transparency * Everything is whitespace-delimited * Commas are

    whitespace * Prefix notation means there are very few reserved characters Calls (callee arg arg arg) (callee (callee arg) arg arg) (capitalize "park assist") (- 10 2 3) by Avi Flax • avi@aviflax.com • August 2017
  9. Functions ;; Syntax: (fn [arg-1 arg-2] body) ;; Example: (fn

    [a b] (+ a b)) by Avi Flax • avi@aviflax.com • August 2017
  10. Vars ;; Syntax: (def name value) ;; Example: (def default-max-connections

    10) by Avi Flax • avi@aviflax.com • August 2017
  11. Functions in Vars ;; Syntax: (def function-name (fn [arg-1 arg-2]

    body)) ;; Example: (def add (fn [a b] (+ a b))) ;; Sugar: (defn add [a b] (+ a b)) by Avi Flax • avi@aviflax.com • August 2017
  12. Everything is an Expression (defn hello [first-name] (str "Hello "

    first-name (if (= first-name "Avi") "!" "."))) by Avi Flax • avi@aviflax.com • August 2017
  13. * Even try/catch is an expression! Everything is an Expression

    (defn good-bye [first-name] (str "Bye " (try (capitalize first-name) (catch Exception err "<unknown>")))) by Avi Flax • avi@aviflax.com • August 2017
  14. * IMHO Clojureʼs syntax is simpler, more regular, more expressive,

    and more powerful than most languages — definitely including Ruby! * Donʼt even get me started on Rubyʼs blocks :facepalm: Rosetta Slide Case Ruby Clojure Call a function sum(1, 2, 3) (+ 1 2 3) Call a method names.join(',') (join names ",") Define function def uc(s); s.upcase; end (defn uc [s] (upper-case s)) Anon. function ->(s) { s.upcase } (fn [s] (upper-case s)) Control structures if bar; foo; end (if bar foo) Passing functions ¯\_(ϑ)_/¯ (map uc names) Composing functions ¯\_(ϑ)_/¯ (comp uc reverse) by Avi Flax • avi@aviflax.com • August 2017
  15. Symbolics 3640 lisp machine running the Genera operating system in

    the Retro- Computing Society of RI display at the Vintage Computer Festival East 1.0. Image via WikiMedia Commons. It’s a LISP • Functional • Declarative • Dynamic • Interactive Development → Developer Productivity • Code as Data → Macros • Everything is an expression • Lazy by Avi Flax • avi@aviflax.com • August 2017
  16. * JavaScript: ClojureScript; server-side (Node) or client- side (browsers) *

    Mobile: primarily via ClojureScript + React Native * Serverless: via either ClojureScript+Node or JVM * Embedded: Ferret is a Clojure transpiler that transpiles Clojure to self contained portable ISO C++11. Itʼs verified to run on Arduino, Teensy, SparkFun, NodeMcu. * Erlang: Clojang is a Clojure library that enables Clojure programs to communicate with Erlang processes It’s Got Reach • JVM • CLR • JavaScript • Mobile • Serverless • Embedded • Erlang by Avi Flax • avi@aviflax.com • August 2017
  17. It’s Mature • 10 years • host platforms: 20+ years

    • 10 major releases • Vibrant community • Rich ecosystem • Interoperability • Strong stewardship by Avi Flax • avi@aviflax.com • August 2017
  18. Immutability • Baked in at the deepest level • Encourages

    rigorous thinking about where/when/why mutable state • Enables (powerful + simple + safe) concurrency • Escape hatches for performance • Deeper, longer-term benefits by Avi Flax • avi@aviflax.com • August 2017
  19. * “Clojureʼs reference model clearly separates identities from values.” (Programming

    Clojure, 3rd Ed.) * 4 different kinds of references for different cases Concurrency • Immutability • References • Software Transactional Memory • Atoms • Agents • Vars • CSP: lightweight routines and channels by Avi Flax • avi@aviflax.com • August 2017
  20. * Performance: you can add type hints, transients, etc *

    Correctness: specifications Scalability • Scripts • Prototypes • Products • Platforms • Performance • Correctness by Avi Flax • avi@aviflax.com • August 2017
  21. Maintainability • Simplicity • Data Orientation • Coherence • Polymorphism

    • Protocols • Multimethods • Records • Specifications • Property Testing by Avi Flax • avi@aviflax.com • August 2017
  22. * — I think. Now what? • Videos! • Simple

    Made Easy by Rich Hickey • Clojure in 10 Big Ideas by Stuart Halloway • Clojure for Rubyists — Accessing the GitHub API by Jeff Terrell* by Avi Flax • avi@aviflax.com • August 2017
  23. Clojure is ⚡Awesome⚡! You should try it! tryclj.com by Avi

    Flax • avi@aviflax.com • August 2017