clojure - why does it matter?
DESCRIPTION
An introduction to Clojure at why you should take a closer look.TRANSCRIPT
![Page 1: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/1.jpg)
ClojureWhy does it matter?
@friemens
![Page 2: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/2.jpg)
● Published 2008 by Rich Hickey.
● Dynamically typed.
● Compiles to bytecode.
A pragmatic Lisp for the JVM
![Page 3: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/3.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 4: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/4.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 5: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/5.jpg)
Few ubiquitous data structures and powerful core library.
Simple Complicated
Data encapsulated behind specific APIs of OO classes.
Immutable data. Mutable class instances & synchronization.
Embedded „code generators“.
External DSL tooling.
Pure functions. Side effects & dependence on context.
![Page 6: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/6.jpg)
Design is deconstruction
Small libraries,no big frameworks!
HTTPserver
Middle-warefunctions
Routingfunction
Handlerfunctions
Page renderer
![Page 7: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/7.jpg)
Deconstructing the database
DatomicA modular, facts-baseddatabase system.
Storage service
TransactorQuery Cache
Peer library
Application
Database
![Page 8: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/8.jpg)
State and Identity
OO style (conflated) Clojure style (separated)
![Page 9: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/9.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 10: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/10.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 11: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/11.jpg)
Huh? Lisp?
Lisp!
Other Languages
Time
Expressive Power
![Page 12: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/12.jpg)
The elegance of Lisp
![Page 13: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/13.jpg)
http://xkcd.com/297
![Page 14: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/14.jpg)
Functional programming
Functions as values
Powerful data structures
„[...] a unit tester's wet dream.“
No assignments
Laziness
![Page 15: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/15.jpg)
Example: Square root approximation
gn+1 := (n/gn + gn) / 2
![Page 16: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/16.jpg)
Concise code
public <K,V> Map<V, K> revertKeysVals(Map<K, V> src) { final Map<V, K> dst = new HashMap<V, K>(); for (Map.Entry<K, V> e : src.entrySet()) { dst.put(e.getValue(), e.getKey()); } return dst;}
(defn revert-kv [m] (->> m (map (juxt second first)) (into {})))
![Page 17: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/17.jpg)
Prefer purity
Pure functions
Side effects
Context
![Page 18: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/18.jpg)
Code is data, or: why does Lisp look different?
Code
Data
![Page 19: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/19.jpg)
Common How it could be
Buildconfig
DSL grammar
Settings
Serialization
XML
Xtext
.properties
JSON
Debugoutput
Anything
EDN
EDN
EDN
EDN
EDN
Clojure is a superset of Extensible Data Notation
![Page 20: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/20.jpg)
A powerful language allows for simpler tools
![Page 21: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/21.jpg)
Interactive development
Demo
![Page 22: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/22.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 23: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/23.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 24: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/24.jpg)
Persistent datastructures
0 1 2 3 4 5 6 6 7 8 9
10
7
![Page 25: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/25.jpg)
Concurrency support
Actor style:Pulsar librarySoftware
TransactionalMemory CSP style:
core.async library
Widely used:Synchronization and LockingJava
Clojure
![Page 26: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/26.jpg)
Advanced libraries
core.logic
core.async
core.typed
core.reducers
Datomic
map + fold parallelized
Logic programming
CSP style programming
Optional type system
Facts-based database
![Page 27: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/27.jpg)
Internal DSLs just happen
HTTP routing
UI form description
Data access
![Page 28: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/28.jpg)
Full stack Clojure
Browser
App Server
Database
ClojureScript
Clojure
Datomic
![Page 29: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/29.jpg)
&Simplicity
Advanced stuff
Lisp
Deconstruction
![Page 30: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/30.jpg)
Advanced thinking
Expressive power
Fosters dev skills
Advanced concurrency support
Perfect for unit testing
What's in for you?
Concise data manipulation
Interactive programming
![Page 31: Clojure - Why does it matter?](https://reader033.vdocuments.us/reader033/viewer/2022042601/554a07bdb4c905557a8b56ea/html5/thumbnails/31.jpg)
Thank you. Questions?
@friemens www.itemis.de