joseph wilk the clojure inside why clojure it was
play

Joseph Wilk The Clojure Inside Why Clojure? It was Functional - PowerPoint PPT Presentation

Joseph Wilk The Clojure Inside Why Clojure? It was Functional Immutable there! Simple LISP Concurrency It was Functional Immutable there! Simple LISP Concurrency Programming Language Computer LISP Hurts (Pick languages that


  1. Joseph Wilk

  2. The Clojure Inside

  3. Why Clojure?

  4. It was Functional Immutable there! Simple LISP Concurrency

  5. It was Functional Immutable there! Simple LISP Concurrency

  6. Programming Language Computer

  7. LISP Hurts (Pick languages that challenge your mental model) (( ))

  8. ( defn filter "Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects." {:added "1.0" :static true} ([pred coll] ( lazy-seq (when-let [s (seq coll)] ( if ( chunked-seq? s) ( let [c ( chunk-first s) size (count c) b ( chunk-buffer size)] (dotimes [i size] (when ( pred ( .nth c i)) ( chunk-append b ( .nth c i)))) ( chunk-cons ( chunk b) (filter pred ( chunk-rest s)))) ( let [f (first s) r (rest s)] ( if ( pred f) (cons f (filter pred r)) (filter pred r))))))))

  9. ( defmacro doseq "Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil." Code {:added "1.0"} generation [seq-exprs & body] ( assert-args (vector? seq-exprs) "a vector for its binding" ( even? (count seq-exprs)) "an even number of forms in binding vector") Functions what do functions ( let [step ( fn step [recform exprs] (if-not exprs [true ` ( do ~@ body)] ( let [k (first exprs) wee v (second exprs)] wee Code is data ( if (keyword? k) wee ( let [steppair ( step recform ( nnext exprs)) Data is code wee needrec ( steppair 0) subform ( steppair 1)] wee ( cond wee (= k :let) [needrec ` ( let ~ v ~ subform)] wee (= k :while) [false ` (when ~ v ~ subform wee ~@ (when needrec [recform]))] wee (= k :when) [false ` ( if ~ v ( do ~ subform ~@ (when needrec [recform])) ~ recform)])) ( let [seq- (gensym "seq_") Variable chunk- (with-meta (gensym "chunk_") generation {:tag 'clojure.lang.IChunk}) count- (gensym "count_") i- (gensym "i_") Is that a recform ` ( recur (next ~ seq-) nil 0 0) class? steppair ( step recform ( nnext exprs)) needrec ( steppair 0) subform ( steppair 1) recform-chunk ` ( recur ~ seq- ~ chunk- ~ count- ( unchecked-inc ~ i-))

  10. OH MY ITS FAST (Jetty/Netty but sssssh) (Shhh confirmation Bias)

  11. History

  12. Rails Me

  13. Rails Me

  14. Ruby

  15. Small Replaceable Pieces

  16. Experiment A ? B Opening Closing Exploring (Divergent) (Convergent) (Emergent)

  17. Clojure

  18. Hystrix https://github.com/Netflix/Hystrix Turbine https://github.com/Netflix/Turbine RxJava https://github.com/Netflix/RxJava Netty http://netty.io Aleph https://github.com/ztellman/aleph Compojure https://github.com/weavejester/compojure Ring https://github.com/ring-clojure/ring Midje https://github.com/marick/Midje

  19. Brevity Maturity + & Denial (its not Java)

  20. cons quote cdr atom eq label car apply cond lambda

  21. Java Denial (defmacro)

  22. HttpServer server = HttpServer.create(address, 0) server.createContext(path, handler); server.setExecutor(null) server.start(); (doto (HttpServer/create address 0) (.createContext path handler) (.setExecutor nil) (.start))

  23. HttpServer server = HttpServer.create(address, 0) server.createContext(path, handler); server.setExecutor(null) server.start(); (doto (HttpServer/create address 0) (.createContext path handler) (.setExecutor nil) (.start))

  24. public class GetSoundCmd extends HystrixCommand<Sound> { private final HttpClient client; private final String urn; public FindSoundCmd(HttpClient client, String urn){ this.client = client; this.urn = urn; } @Override protected Sound run(){ return client.get("/sounds/" + urn, Sound.class) } @Override protected Sound getFallback(){ return Sound.missing(id); } } new GetUserCmd(client, id).execute(); (:require [com.netflix.hystrix.core :as hystrix]) (hystrix/defcommand find-sound {:hystrix/fallback-fn #(constantly {}))} [client urn] (http/get urn)) (get-sound client "soundcloud:sounds:123")

  25. public class GetSoundCmd extends HystrixCommand<Sound> { private final HttpClient client; private final String urn; public FindSoundCmd(HttpClient client, String urn){ this.client = client; this.urn = urn; } @Override protected Sound run(){ return client.get("/sounds/" + urn, Sound.class) } @Override protected Sound getFallback(){ return Sound.missing(id); } } new GetUserCmd(client, id).execute(); (:require [com.netflix.hystrix.core :as hystrix]) (hystrix/defcommand find-sound {:hystrix/fallback-fn #(constantly {}))} [client urn] (http/get urn)) (get-sound client "soundcloud:sounds:123")

  26. Interactivity R read E evaluate P print L loop

  27. Services at scale

  28. Grace in the face of failure high partition tolerance in a high latency cloud network (don't trust anything works)

  29. Threadpool (future (fn [] "from the future")) (promise) (agent)

  30. Bulkhead Threadpool Threadpool Scheduler 100 threads 10 threads queue Threadpool Threadpool 10 threads 30 threads

  31. (defn find-user [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (hystrix/defcommand find-user {:hystrix/fallback-fn (constantly {})} [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (find-user 123) (hystrix/queue #‘find-user 123)

  32. (defn find-user [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (hystrix/defcommand find-user {:hystrix/fallback-fn (constantly {})} [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (find-user 123) (hystrix/queue #‘find-user 123)

  33. (defn find-user [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (hystrix/defcommand find-user {:hystrix/fallback-fn (constantly {})} [user-urn] (let [response (get-user user-urn)] (if (= 200 (:status response)) (:body response) {}))) (find-user 123) (hystrix/queue #‘find-user 123)

  34. Service X Service X Service X Turbine Dashboard Consumers metrics Service X discovery Service X DNS

  35. https://github.com/Netflix/Hystrix

  36. Compositional Complexity

  37. a b c d e f g

  38. a b c d e f g

  39. List Processing b map d g zip e zip a c

  40. List Processing b map d g zip e zip a c

  41. LisP b map d g zip e zip a c

  42. RxJava (map) (zip) (filter) (partition) (reduce) https://github.com/Netflix/RxJava

  43. Ending Callback Hell b map d g zip e zip a c on-complete on-error (.subscribe (fn [result] (enqueue channel {:status 200 :body (json/encode result}) (fn [error] (log/exception error request))))))

  44. Request & Response (.subscribe (fn [result] (enqueue channel {:status 200 :body (json/encode result}) (fn [error] (log/exception error request)))))) ( defn handler [request] {:status 200 :body "Hello World"}) ( use 'lamina.core) ( defn handler [response-channel request] ( enqueue response-channel {:status 200 :body "Hello World"})) https://github.com/ztellman/aleph

  45. Request & Response (.subscribe (fn [result] (enqueue channel {:status 200 :body (json/encode result}) (fn [error] (log/exception error request)))))) ( defn handler [request] {:status 200 :body "Hello World"}) ( use 'lamina.core) ( defn handler [response-channel request] ( enqueue response-channel {:status 200 :body "Hello World"})) https://github.com/ztellman/aleph

  46. Request & Response (.subscribe (fn [result] (enqueue channel {:status 200 :body (json/encode result}) (fn [error] (log/exception error request)))))) ( defn handler [request] {:status 200 :body "Hello World"}) ( use 'lamina.core) ( defn handler [response-channel request] ( enqueue response-channel {:status 200 :body "Hello World"})) https://github.com/ztellman/aleph

  47. Request & Response (.subscribe (fn [result] (enqueue channel {:status 200 :body (json/encode result}) (fn [error] (log/exception error request)))))) ( defn handler [request] {:status 200 :body "Hello World"}) ( use 'lamina.core) ( defn handler [response-channel request] ( enqueue response-channel {:status 200 :body "Hello World"})) https://github.com/ztellman/aleph

  48. Its upside down attern matching Clojure Itches parameter redeye Corrupts your brain

  49. Clojure One of the many paths

  50. Joseph Wilk

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend