Clojure - Why does it matter?

Post on 06-May-2015

650 views 3 download

description

An introduction to Clojure at why you should take a closer look.

Transcript of Clojure - Why does it matter?

ClojureWhy does it matter?

@friemens

● Published 2008 by Rich Hickey.

● Dynamically typed.

● Compiles to bytecode.

A pragmatic Lisp for the JVM

&Simplicity

Advanced stuff

Lisp

Deconstruction

&Simplicity

Advanced stuff

Lisp

Deconstruction

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.

Design is deconstruction

Small libraries,no big frameworks!

HTTPserver

Middle-warefunctions

Routingfunction

Handlerfunctions

Page renderer

Deconstructing the database

DatomicA modular, facts-baseddatabase system.

Storage service

TransactorQuery Cache

Peer library

Application

Database

State and Identity

OO style (conflated) Clojure style (separated)

&Simplicity

Advanced stuff

Lisp

Deconstruction

&Simplicity

Advanced stuff

Lisp

Deconstruction

Huh? Lisp?

Lisp!

Other Languages

Time

Expressive Power

The elegance of Lisp

http://xkcd.com/297

Functional programming

Functions as values

Powerful data structures

„[...] a unit tester's wet dream.“

No assignments

Laziness

Example: Square root approximation

gn+1 := (n/gn + gn) / 2

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 {})))

Prefer purity

Pure functions

Side effects

Context

Code is data, or: why does Lisp look different?

Code

Data

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

A powerful language allows for simpler tools

Interactive development

Demo

&Simplicity

Advanced stuff

Lisp

Deconstruction

&Simplicity

Advanced stuff

Lisp

Deconstruction

Persistent datastructures

0 1 2 3 4 5 6 6 7 8 9

10

7

Concurrency support

Actor style:Pulsar librarySoftware

TransactionalMemory CSP style:

core.async library

Widely used:Synchronization and LockingJava

Clojure

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

Internal DSLs just happen

HTTP routing

UI form description

Data access

Full stack Clojure

Browser

App Server

Database

ClojureScript

Clojure

Datomic

&Simplicity

Advanced stuff

Lisp

Deconstruction

Advanced thinking

Expressive power

Fosters dev skills

Advanced concurrency support

Perfect for unit testing

What's in for you?

Concise data manipulation

Interactive programming

Thank you. Questions?

@friemens www.itemis.de