SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
Full	
  Stack	
  Clojure	
  
Michiel	
  Borkent	
  	
  
@borkdude	
  
HAN	
  University	
  of	
  Applied	
  Sciences	
  
October	
  1st	
  2015	
  
Agenda	
  
●  Part	
  1:	
  Why	
  Clojure	
  
●  Part	
  2:	
  Some	
  basic	
  Clojure	
  
●  Part	
  3:	
  Full	
  stack	
  Clojure	
  
Part	
  1:	
  Why	
  Clojure	
  
Clojure	
  
•  Designed	
  by	
  Rich	
  Hickey	
  in	
  2007	
  
•  FrustraNon	
  with	
  Java,	
  C++	
  
•  Deliver	
  the	
  same	
  funcNonality	
  faster	
  
•  Without	
  giving	
  up	
  operaNonal	
  requirements	
  	
  
Non-­‐goals	
  
•  Easy	
  to	
  learn	
  by	
  Java	
  etc.	
  developers	
  
•  Experiment	
  in	
  language	
  design	
  
Programs	
  are	
  (mostly)	
  about	
  data	
  
•  Language	
  should	
  not	
  get	
  in	
  the	
  way	
  of	
  data	
  
•  Good	
  support	
  for	
  data	
  literals	
  
•  Data	
  transformaNons	
  
•  Data	
  is	
  immutable	
  
•  OO	
  is	
  not	
  great	
  for	
  working	
  with	
  data	
  
•  Big	
  part	
  of	
  program	
  can	
  be	
  built	
  using	
  plain	
  data	
  
	
  
Systems	
  and	
  immutability	
  
•  Each	
  system	
  receives	
  a	
  message	
  
and/or	
  sends	
  a	
  message	
  
•  MutaNng	
  a	
  message	
  does	
  not	
  
affect	
  other	
  system	
  
•  In	
  Java,	
  references	
  lead	
  to	
  
uncontrolled	
  mutaNon	
  
•  You	
  can	
  protect	
  yourself	
  by	
  using	
  
Value	
  Objects	
  or	
  DTOs,	
  but	
  takes	
  
work	
  
•  Clojure	
  adopts	
  system	
  model	
  
in	
  the	
  small	
  by	
  using	
  
immutable	
  data	
  structures	
  
•  MutaNon	
  only	
  happens	
  in	
  
controlled	
  and	
  explicit	
  ways	
  
Clojure	
  
•  dynamic	
  language	
  
•  lisp	
  
•  funcNonal	
  programming	
  
•  immutable	
  data	
  structures	
  
•  strong	
  concurrency	
  support	
  
•  embraces	
  host	
  pla_orm	
  (JVM,	
  js)	
  
•  EDN	
  
Choosing	
  a	
  language	
  is	
  all	
  about	
  trade	
  offs!	
  
	
  
Clojure	
  in	
  industry	
  
hcps://www.youtube.com/watch?v=av9Xi6CNqq4	
  
	
  
http://dev.clojure.org/display/community/Clojure+Success+Stories
http://clojure.org/Companies
Part	
  2:	
  Basic	
  Clojure	
  
Data	
  literals	
  
Keyword:	
  	
  	
  	
  	
  :a	
  
Vector:	
  	
  	
  	
  	
  [1	
  2	
  3	
  4]	
  
Hash	
  map:	
  	
  	
  {:a	
  1,	
  :b	
  2}	
  
Set:	
  	
  	
  	
  	
  	
  	
  	
  #{1	
  2	
  3	
  4}	
  
List:	
  	
  	
  	
  	
  	
  	
  '(1	
  2	
  3	
  4)	
  
Extensible	
  Data	
  NotaFon	
  
{:key1"Bar"	
  
	
  :key2	
  [1	
  2	
  3]	
  
	
  "key3",	
  #{1.0	
  2.0	
  c}	
  
	
  :key4,{:foo	
  {:bar	
  {:baz	
  'hello}}}}	
  	
  
	
  
(pr-­‐str	
  {:foo	
  "bar"})	
  
(read-­‐string	
  "{:foo	
  "bar"}")	
  
	
  
f(x)	
  -­‐>	
  (f	
  x)	
  
	
  
Syntax	
  
Syntax	
  
if	
  (...)	
  {	
  
	
  	
  ...	
  
}	
  else	
  {	
  	
  	
  	
  	
  	
  	
  -­‐>	
  
	
  	
  ...	
  	
  
}	
  
	
  
(if	
  ...	
  
	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  ...)	
  
Syntax	
  
var	
  foo	
  =	
  "bar";	
  	
  
	
  
(def	
  foo	
  "bar")	
  
JavaScript	
  -­‐	
  ClojureScript	
  
if	
  (bugs.length	
  >	
  0)	
  {	
  
	
  	
  return	
  'Not	
  ready	
  for	
  release';	
  
}	
  else	
  {	
  
	
  	
  return	
  'Ready	
  for	
  release';	
  
}	
  
	
  
(if	
  (pos?	
  (count	
  bugs))	
  
	
  	
  "Not	
  ready	
  for	
  release"	
  
	
  	
  "Ready	
  for	
  release")	
  
source:	
  hcp://himera.herokuapp.com/synonym.html	
  
JavaScript	
  -­‐	
  ClojureScript	
  
var	
  foo	
  =	
  {bar:	
  "baz"};	
  
foo.bar	
  =	
  "baz";	
  
foo["abc"]	
  =	
  17;	
  
	
  
alert('foo')	
  
new	
  Date().getTime()	
  
new	
  
Date().getTime().toString()	
  
	
  
	
  
(def	
  foo	
  (js-­‐obj	
  "bar"	
  "baz"))	
  
(set!	
  (.-­‐bar	
  foo)	
  "baz")	
  
(aset	
  foo	
  "abc"	
  17)	
  
	
  
(js/alert	
  "foo")	
  
(.getTime	
  (js/Date.))	
  
(..	
  (js/Date.)	
  (getTime)	
  
(toString))	
  
source:	
  hcp://himera.herokuapp.com/synonym.html	
  
Persistent	
  data	
  structures	
  
(def	
  v	
  [1	
  2	
  3])	
  
(conj	
  v	
  4)	
  ;;	
  =>	
  [1	
  2	
  3	
  4]	
  
(get	
  v	
  0)	
  ;;	
  =>	
  1	
  
(v	
  0)	
  ;;	
  =>	
  1	
  
	
  
source:	
  hcp://hypirion.com/musings/understanding-­‐persistent-­‐vector-­‐pt-­‐1	
  	
  
Persistent	
  data	
  structures	
  
(def	
  m	
  {:foo	
  1	
  :bar	
  2})	
  
(assoc	
  m	
  :foo	
  2)	
  ;;	
  =>	
  {:foo	
  2	
  :bar	
  2}	
  
(get	
  m	
  :foo)	
  ;;=>	
  1	
  
(m	
  :foo)	
  ;;=>	
  1	
  
(:foo	
  m)	
  ;;=>	
  1	
  
(dissoc	
  m	
  :foo)	
  ;;=>	
  {:bar	
  2}	
  
FuncFonal	
  programming	
  
(def	
  r	
  (-­‐>>	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (range	
  10)	
  	
  	
  	
  ;;	
  (0	
  1	
  2	
  ..	
  9)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (filter	
  odd?)	
  ;;	
  (1	
  3	
  5	
  7	
  9)	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  (map	
  inc)))	
  	
  	
  ;;	
  (2	
  4	
  6	
  8	
  10)	
  	
  
;;	
  r	
  is	
  (2	
  4	
  6	
  8	
  10)	
  
	
  
FuncFonal	
  programming	
  
;;	
  r	
  is	
  (2	
  4	
  6	
  8	
  10)	
  
(reduce	
  +	
  r)	
  	
  
;;	
  =>	
  30	
  
(reductions	
  +	
  r)	
  
;;	
  =>	
  (2	
  6	
  12	
  20	
  30)	
  
	
  
	
  
	
  
var	
  sum	
  =	
  _.reduce(r,	
  function(memo,	
  num){	
  return	
  memo	
  +	
  num;	
  });	
  
Sequence	
  abstracFon	
  
Data	
  structures	
  as	
  seqs	
  
(first	
  [1	
  2	
  3])	
  ;;=>	
  1	
  
(rest	
  [1	
  2	
  3])	
  ;;=>	
  (2	
  3)	
  
General	
  seq	
  funcNons:	
  map,	
  reduce,	
  filter,	
  ...	
  
(distinct	
  [1	
  1	
  2	
  3])	
  ;;=>	
  (1	
  2	
  3)	
  
(take	
  2	
  (range	
  10))	
  ;;=>	
  (0	
  1)	
  
	
  
See	
  hcp://clojure.org/cheatsheet	
  for	
  more	
  	
  
Sequence	
  abstracFon	
  
Most	
  seq	
  funcNons	
  return	
  lazy	
  sequences:	
  
	
  
(take	
  2	
  (map	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (fn	
  [n]	
  (js/alert	
  n)	
  n)	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (range)))	
  
	
   infinite	
  lazy	
  sequence	
  of	
  numbers	
  
side	
  effect	
  
Mutable	
  state:	
  atoms	
  
(def	
  my-­‐atom	
  (atom	
  0))	
  
@my-­‐atom	
  ;;	
  0	
  
(reset!	
  my-­‐atom	
  1)	
  
(reset!	
  my-­‐atom	
  (inc	
  @my-­‐atom))	
  ;;	
  bad	
  idiom	
  
(swap!	
  my-­‐atom	
  (fn	
  [old-­‐value]	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  (inc	
  old-­‐value)))	
  
(swap!	
  my-­‐atom	
  inc)	
  ;;	
  same	
  
@my-­‐atom	
  ;;	
  4	
  
	
  
Lisp:	
  macros	
  
(map	
  inc	
  	
  
	
  	
  (filter	
  odd?	
  	
  
	
  	
  	
  	
  (range	
  10)))	
  
	
  
(-­‐>>	
  	
  
	
  	
  (range	
  10)	
  
	
  	
  (filter	
  odd?)	
  
	
  	
  (map	
  inc))	
  
thread	
  last	
  macro	
  
Lisp:	
  macros	
  
(macroexpand	
  	
  
	
  	
  '(-­‐>>	
  (range	
  10)	
  (filter	
  odd?)))	
  
	
  
;;	
  =>	
  (filter	
  odd?	
  (range	
  10))	
  
	
  
(macroexpand	
  	
  
	
  	
  '(-­‐>>	
  (range	
  10)	
  (filter	
  odd?)	
  (map	
  inc)))	
  
	
  
;;	
  =>	
  (map	
  inc	
  (filter	
  odd?	
  (range	
  10)))	
  
	
  
Lisp:	
  macros	
  
JVM	
  Clojure:	
  
	
  
(defmacro	
  defonce	
  [x	
  init]	
  
	
  `(when-­‐not	
  (exists?	
  ~x)	
  
	
  	
  	
  	
  (def	
  ~x	
  ~init)))	
  
	
  
	
  
ClojureScript:	
  
	
  
(defonce	
  foo	
  1)	
  
(defonce	
  foo	
  2)	
  ;;	
  no	
  effect	
  
notes:	
  	
  
●  macros	
  must	
  be	
  wricen	
  in	
  JVM	
  Clojure	
  
●  are	
  expanded	
  at	
  compile	
  Nme	
  
●  generated	
  code	
  gets	
  executes	
  in	
  ClojureScript	
  
Part	
  3:	
  Full	
  Stack	
  Clojure	
  
Full	
  Stack	
  Clojure 	
  	
  
Front-end (js)
ClojureScript
reagent + react
secretary
cljs-http
figwheel
REPL
leiningen
core.async
Prismatic/Schema
timbre
Server side (JVM)
Clojure
ring
compojure
liberator
environ
hiccup
Framework: Pedestal
Persistence RDBMS (via JDBC, e.g. PostgresQL, MySQL, H2, etc)
clojure.java.jdbc
YesQL
Datomic
Show	
  me	
  the	
  code!	
  
https://github.com/borkdude/full-stack-clojure-han-okt-2015
Get	
  started	
  with	
  Clojure(Script)	
  
•  Read	
  a	
  Clojure(Script)	
  book	
  
•  Do	
  the	
  4clojure	
  exercises	
  
•  Start	
  hacking	
  on	
  your	
  own	
  project	
  
•  Pick	
  an	
  online	
  Clojure	
  course 	
  	
  
•  Join	
  the	
  AMSCLJ	
  meetup	
  
•  Join	
  the	
  Slack	
  community	
  
	
  

Contenu connexe

Tendances

Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simpleJohn Stevenson
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Sergey Platonov
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enoughNati Cohen
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstractionSergey Platonov
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scalaRuslan Shevchenko
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash FeaturesNati Cohen
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by exampleYunWon Jeong
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeSteffen Wenz
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory ManagementAlan Uthoff
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMarcelo Gornstein
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Introthnetos
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnMoriyoshi Koizumi
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Steffen Wenz
 

Tendances (20)

Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Clojure made really really simple
Clojure made really really simpleClojure made really really simple
Clojure made really really simple
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
When RegEx is not enough
When RegEx is not enoughWhen RegEx is not enough
When RegEx is not enough
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
Gor Nishanov,  C++ Coroutines – a negative overhead abstractionGor Nishanov,  C++ Coroutines – a negative overhead abstraction
Gor Nishanov, C++ Coroutines – a negative overhead abstraction
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Naughty And Nice Bash Features
Naughty And Nice Bash FeaturesNaughty And Nice Bash Features
Naughty And Nice Bash Features
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 
Modern c++ Memory Management
Modern c++ Memory ManagementModern c++ Memory Management
Modern c++ Memory Management
 
Minion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejsMinion pool - a worker pool for nodejs
Minion pool - a worker pool for nodejs
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Hacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 AutumnHacking Go Compiler Internals / GoCon 2014 Autumn
Hacking Go Compiler Internals / GoCon 2014 Autumn
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 

Similaire à Full Stack Clojure

Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science Chucheng Hsieh
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMsunng87
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx FranceDavid Delabassee
 
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...confluent
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)jaxLondonConference
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)Jacek Laskowski
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Phil Calçado
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate CompilersFunctional Thursday
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議dico_leque
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataAnne Nicolas
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelVitaly Nikolenko
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Big data shim
Big data shimBig data shim
Big data shimtistrue
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojurePaul Lam
 

Similaire à Full Stack Clojure (20)

Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Modern technologies in data science
Modern technologies in data science Modern technologies in data science
Modern technologies in data science
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Clojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVMClojure: Practical functional approach on JVM
Clojure: Practical functional approach on JVM
 
55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France55 new things in Java 7 - Devoxx France
55 new things in Java 7 - Devoxx France
 
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
Data-Oriented Programming with Clojure and Jackdaw (Charles Reese, Funding Ci...
 
The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)The Curious Clojurist - Neal Ford (Thoughtworks)
The Curious Clojurist - Neal Ford (Thoughtworks)
 
(map Clojure everyday-tasks)
(map Clojure everyday-tasks)(map Clojure everyday-tasks)
(map Clojure everyday-tasks)
 
Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)Lisp Macros in 20 Minutes (Featuring Clojure)
Lisp Macros in 20 Minutes (Featuring Clojure)
 
Java
JavaJava
Java
 
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
[FT-11][suhorng] “Poor Man's” Undergraduate Compilers
 
Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議Meta-objective Lisp @名古屋 Reject 会議
Meta-objective Lisp @名古屋 Reject 会議
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Big data shim
Big data shimBig data shim
Big data shim
 
A gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojureA gentle introduction to functional programming through music and clojure
A gentle introduction to functional programming through music and clojure
 

Dernier

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 

Dernier (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 

Full Stack Clojure

  • 1. Full  Stack  Clojure   Michiel  Borkent     @borkdude   HAN  University  of  Applied  Sciences   October  1st  2015  
  • 2. Agenda   ●  Part  1:  Why  Clojure   ●  Part  2:  Some  basic  Clojure   ●  Part  3:  Full  stack  Clojure  
  • 3. Part  1:  Why  Clojure  
  • 4. Clojure   •  Designed  by  Rich  Hickey  in  2007   •  FrustraNon  with  Java,  C++   •  Deliver  the  same  funcNonality  faster   •  Without  giving  up  operaNonal  requirements    
  • 5. Non-­‐goals   •  Easy  to  learn  by  Java  etc.  developers   •  Experiment  in  language  design  
  • 6. Programs  are  (mostly)  about  data   •  Language  should  not  get  in  the  way  of  data   •  Good  support  for  data  literals   •  Data  transformaNons   •  Data  is  immutable   •  OO  is  not  great  for  working  with  data   •  Big  part  of  program  can  be  built  using  plain  data    
  • 7. Systems  and  immutability   •  Each  system  receives  a  message   and/or  sends  a  message   •  MutaNng  a  message  does  not   affect  other  system   •  In  Java,  references  lead  to   uncontrolled  mutaNon   •  You  can  protect  yourself  by  using   Value  Objects  or  DTOs,  but  takes   work   •  Clojure  adopts  system  model   in  the  small  by  using   immutable  data  structures   •  MutaNon  only  happens  in   controlled  and  explicit  ways  
  • 8. Clojure   •  dynamic  language   •  lisp   •  funcNonal  programming   •  immutable  data  structures   •  strong  concurrency  support   •  embraces  host  pla_orm  (JVM,  js)   •  EDN  
  • 9. Choosing  a  language  is  all  about  trade  offs!    
  • 10. Clojure  in  industry   hcps://www.youtube.com/watch?v=av9Xi6CNqq4     http://dev.clojure.org/display/community/Clojure+Success+Stories http://clojure.org/Companies
  • 11. Part  2:  Basic  Clojure  
  • 12. Data  literals   Keyword:          :a   Vector:          [1  2  3  4]   Hash  map:      {:a  1,  :b  2}   Set:                #{1  2  3  4}   List:              '(1  2  3  4)  
  • 13. Extensible  Data  NotaFon   {:key1"Bar"    :key2  [1  2  3]    "key3",  #{1.0  2.0  c}    :key4,{:foo  {:bar  {:baz  'hello}}}}       (pr-­‐str  {:foo  "bar"})   (read-­‐string  "{:foo  "bar"}")    
  • 14. f(x)  -­‐>  (f  x)     Syntax  
  • 15. Syntax   if  (...)  {      ...   }  else  {              -­‐>      ...     }     (if  ...          ...          ...)  
  • 16. Syntax   var  foo  =  "bar";       (def  foo  "bar")  
  • 17. JavaScript  -­‐  ClojureScript   if  (bugs.length  >  0)  {      return  'Not  ready  for  release';   }  else  {      return  'Ready  for  release';   }     (if  (pos?  (count  bugs))      "Not  ready  for  release"      "Ready  for  release")   source:  hcp://himera.herokuapp.com/synonym.html  
  • 18. JavaScript  -­‐  ClojureScript   var  foo  =  {bar:  "baz"};   foo.bar  =  "baz";   foo["abc"]  =  17;     alert('foo')   new  Date().getTime()   new   Date().getTime().toString()       (def  foo  (js-­‐obj  "bar"  "baz"))   (set!  (.-­‐bar  foo)  "baz")   (aset  foo  "abc"  17)     (js/alert  "foo")   (.getTime  (js/Date.))   (..  (js/Date.)  (getTime)   (toString))   source:  hcp://himera.herokuapp.com/synonym.html  
  • 19. Persistent  data  structures   (def  v  [1  2  3])   (conj  v  4)  ;;  =>  [1  2  3  4]   (get  v  0)  ;;  =>  1   (v  0)  ;;  =>  1    
  • 21. Persistent  data  structures   (def  m  {:foo  1  :bar  2})   (assoc  m  :foo  2)  ;;  =>  {:foo  2  :bar  2}   (get  m  :foo)  ;;=>  1   (m  :foo)  ;;=>  1   (:foo  m)  ;;=>  1   (dissoc  m  :foo)  ;;=>  {:bar  2}  
  • 22. FuncFonal  programming   (def  r  (-­‐>>                      (range  10)        ;;  (0  1  2  ..  9)                    (filter  odd?)  ;;  (1  3  5  7  9)                    (map  inc)))      ;;  (2  4  6  8  10)     ;;  r  is  (2  4  6  8  10)    
  • 23. FuncFonal  programming   ;;  r  is  (2  4  6  8  10)   (reduce  +  r)     ;;  =>  30   (reductions  +  r)   ;;  =>  (2  6  12  20  30)         var  sum  =  _.reduce(r,  function(memo,  num){  return  memo  +  num;  });  
  • 24. Sequence  abstracFon   Data  structures  as  seqs   (first  [1  2  3])  ;;=>  1   (rest  [1  2  3])  ;;=>  (2  3)   General  seq  funcNons:  map,  reduce,  filter,  ...   (distinct  [1  1  2  3])  ;;=>  (1  2  3)   (take  2  (range  10))  ;;=>  (0  1)     See  hcp://clojure.org/cheatsheet  for  more    
  • 25. Sequence  abstracFon   Most  seq  funcNons  return  lazy  sequences:     (take  2  (map                        (fn  [n]  (js/alert  n)  n)                            (range)))     infinite  lazy  sequence  of  numbers   side  effect  
  • 26. Mutable  state:  atoms   (def  my-­‐atom  (atom  0))   @my-­‐atom  ;;  0   (reset!  my-­‐atom  1)   (reset!  my-­‐atom  (inc  @my-­‐atom))  ;;  bad  idiom   (swap!  my-­‐atom  (fn  [old-­‐value]                                      (inc  old-­‐value)))   (swap!  my-­‐atom  inc)  ;;  same   @my-­‐atom  ;;  4    
  • 27. Lisp:  macros   (map  inc        (filter  odd?            (range  10)))     (-­‐>>        (range  10)      (filter  odd?)      (map  inc))   thread  last  macro  
  • 28. Lisp:  macros   (macroexpand        '(-­‐>>  (range  10)  (filter  odd?)))     ;;  =>  (filter  odd?  (range  10))     (macroexpand        '(-­‐>>  (range  10)  (filter  odd?)  (map  inc)))     ;;  =>  (map  inc  (filter  odd?  (range  10)))    
  • 29. Lisp:  macros   JVM  Clojure:     (defmacro  defonce  [x  init]    `(when-­‐not  (exists?  ~x)          (def  ~x  ~init)))       ClojureScript:     (defonce  foo  1)   (defonce  foo  2)  ;;  no  effect   notes:     ●  macros  must  be  wricen  in  JVM  Clojure   ●  are  expanded  at  compile  Nme   ●  generated  code  gets  executes  in  ClojureScript  
  • 30. Part  3:  Full  Stack  Clojure  
  • 31. Full  Stack  Clojure     Front-end (js) ClojureScript reagent + react secretary cljs-http figwheel REPL leiningen core.async Prismatic/Schema timbre Server side (JVM) Clojure ring compojure liberator environ hiccup Framework: Pedestal Persistence RDBMS (via JDBC, e.g. PostgresQL, MySQL, H2, etc) clojure.java.jdbc YesQL Datomic
  • 32. Show  me  the  code!   https://github.com/borkdude/full-stack-clojure-han-okt-2015
  • 33. Get  started  with  Clojure(Script)   •  Read  a  Clojure(Script)  book   •  Do  the  4clojure  exercises   •  Start  hacking  on  your  own  project   •  Pick  an  online  Clojure  course     •  Join  the  AMSCLJ  meetup   •  Join  the  Slack  community