SlideShare a Scribd company logo
1 of 62
Download to read offline
Clojure in Real Life 
Tommi Reiman / Metosin 
17.10.2014
Agenda 
• Clojure basics 
• In Real Life 
• Getting started 
• Q  A
Clojure Basics
Clojure 
• Clojure is a dynamic, functional, general purpose language 
– Compiled, strong (dynamic) typing 
• with optional static typing (core.typed) 
– Targets JVM, CLR and JavaScript 
– Immutable, persistent data structures 
– Interactive development (REPL) 
– Concurrency, software transactional memory  core.async 
– Pragmatism over purism 
– Runtime polymorphism 
– A lisp, meta-programming with macros
Syntax
Syntax 
• Heterogeneous read-only data structures 
• All data literals stand for themselves, except Lists  Symbols
Simple program
Immutable, persistent Data
Structural sharing 
h)p://eclipsesource.com/blogs/2009/12/13/persistent-­‐trees-­‐in-­‐git-­‐clojure-­‐and-­‐couchdb-­‐data-­‐structure-­‐convergence/
Macros 
• Macros are evaluated at compile-time (to generate code) 
• One can also (eval) code at runtime 
è Great tools for reducing boilerplate  do concise DSLs 
unless?
Business DSL
Java Interoperability
math speed / hiphip (array)!
Concurrency 
• Immutable data structures, 
pure functions 
• State  Identity separation 
via References 
– Vars, Refs, Atoms, Agents 
• futures, promises, delays 
• Libraries: Avout, Lamina, 
Pulsar, Onyx, (Akka) 
• core.async
STM example 
h)p://sw1nn.com/blog/2012/04/11/clojure-­‐stm-­‐what-­‐why-­‐how/
core.async 
• Library for channel-based async processing 
– Channels, go-blocks, transducers 
• Communicating sequential processes 
• https://golang.org/ 
• Both for threaded (JVM)  non-threaded (JS) 
environments 
– http://swannodette.github.io/2013/08/02/100000-processes/
core.async, example 
• Boiling Sous-Vide Eggs using Clojure's Transducers 
– http://blog.eikeland.se/2014/10/06/pid-transducer/?utm_content=buffer75806
Didn’t cover 
• Protocols, Multimethods 
• Destructuring 
• Dynamic binding 
• Walkers 
• Records 
• Metadata
Missed these too 
• core.match – pattern matching 
• core.typed – gradual (static) typing 
• core.logic – logic programming
Ok, this is just another academic…
In real life
Leiningen 
• Declarative build tool, uses Maven internally
Testing 
• clojure.test (bundled), Midje (TDD/BDD), expectations 
• Clj-webdriver (browser tests) 
• test.check for generative tests 
• Leiningen plugins to generate (junit-)reports, run coverage etc.
Integration testing
Editors 
• We (6) are currently using: 
– IDEA + Cursive 
– Eclipse + CCW 
– Vim + Fireplace 
– Emacs + Cider 
– LightTable 
• Not yet as good as the Java tools, but getting 
better every day
REPL-driven workflow 
• Evaluate code as you go, instant feedback 
– Develop in Editor, evaluate in REPL 
– Ridiculously fast (single-pass) compiler 
• Massive boost in productivity 
• nRepl-servers 
• Browser-Repls
Web stacks 
• Mostly micro-libraries on top of Ring 
– Request, Response, Adapters, Middlewares, Handlers 
– https://github.com/ring-clojure/ring 
• Packaged either: 
– standalone web servers (uberjar) 
– As Servlet Apps (and deploy as wars) 
• Some popular libs 
– Compojure (https://github.com/weavejester/compojure) 
– Liberator (http://clojure-liberator.github.io/liberator/) 
– Pedestal (https://github.com/pedestal/pedestal) 
• Lot’s of support libs (clostache, hiccup, enlive, …)
Simple web server
Schema Sausage?
Sc elements
Demo: a REST API 
• with Compojure-api  Ring-Swagger
... something like this
Don’t trust the benchmark 
Go 
211k 
h)p-­‐kit 
137k 
Compojure 
123k 
Scalatra 
107k 
Play 
98k 
Spring 
42k 
h)p://www.techempower.com/benchmarks/#secKon=data-­‐r9hw=i7test=json
Async web - Scala  Clojure 
h)p://www.slideshare.net/colinlogaan/clojure-­‐at-­‐a-­‐post-­‐office-­‐36333973
Persistence (of time) 
• Idiomatic wrappers on top of Java Libraries 
– RDB: Clojure.java.jdbc, Yesql, Korma 
– Monger (MongoDB), Welle (Riak), Cassaforte 
(Cassandra), Neocons (Neo4j), Carmine (Redis), … 
• Datomic 
Demo
MongoDB sample
Utils 
• Use Java libraries or idiomatic clj-wrappers on 
top of them 
– clj-time, emailer, clj-ssh, timbre (logging)  tons of other 
goodnesses
Data formats 
• JSON maps 1:1 to Clojure 
– All core functions available, no need for external DSLs 
• XML, lazy parsers, zippers, selectors 
• Excel, use Apache POI directly 
• EDN, Transit 
• … 
Demo
Clojurescript 
• Clojure compiled into JavaScript 
– No threads, some different implementation classes 
• Google Closure compiler 
• Browser-repls (http://clojurescript.net/) 
– Same dynamic development flow as with Clojure
Demo: Flappy Bird 
h)ps://github.com/bhauman/flappy-­‐bird-­‐demo
OM / Reagent 
• A ClojureScript interface to Facebook's React.js
Game of Life 
h)p://clj-­‐me.cgrand.net/2011/08/19/conways-­‐game-­‐of-­‐life/
Einstein / Zebra 
h)ps://github.com/swannode)e/logic-­‐tutorial
Sudoku Solver 
h)ps://gist.github.com/swannode)e/3217582
So, do people use it?
Thoughtworks Technology Radar 2014 
Scala, 
adopt! 
Where’s 
my 
clojure?
In Finland? 
• Zenrobotics 
– “the largest clojure codebase in the world”? 
• Metosin 
– Internally, for small  large enterprises, Finnish Authorities 
(with friends)  abroad 
– Training for others (Solita, Gofore, Futurice  others) 
• Solita (with friends) 
• Others 
• (lots of startups)
:stats 
(1.5y 
project, 
5+ 
developers)
Flushing the Brain 
• (Mutable) Objects 
à Immutable Data, (pure) functions, references 
• Design Patterns 
à mostly not needed (builder, strategy, visitor,…), new functional design patterns 
• Domain Driven Design 
à Anemic Domain Model is a Functional Domain Model 
• TDD 
à RDD (with tests) 
• Dependency Injection 
à Thought not needed, but still good for large apps (via Stuart Sierra’s 
Component-library, collecting app state into one place)
Goods and Bads 
• Good 
– Simple and beautiful code 
– Awesome Development speed 
– Great  friendly ecosystem (libs, people  support) 
– The JVM Backup (can use Java anywhere, performance) 
– Clojurescript(!!!) 
– Extensibility (mini languages on top) 
• Bad 
– Startup time 
– CLJS Build tools (vs Gulp) 
– Refactoring in large projects (with current IDE support) 
– 10% times, missing the static type system
I would use Clojure for… 
• Everything, replacing both Java  Scala! 
• Just kidding, not for: 
– Android development (object apis, startup) à Scala/Java 
– Command line apps (slow startup) à whatever 
– Maybe not for distributed computing à Spark/Akka/Scala 
• But Clojure for mostly everything else.
Clojure @ Metosin 
• Open source 
– Ring-Swagger  Compojure-api (Swagger 2.0) 
– kekkonen.io (a snappy CQRS-lib) 
– Lein-simulflow 
• Community 
– Tech talks, seminars, dojos 
• Projects  Training 
• Fun stuff
Getting started
Some resources 
• Books: 
– Clojure Programming 
– The Joy of Clojure, 2nd 
• Online 
– 4clojure (https://www.4clojure.com/) 
– ClojureDocs (http://clojuredocs.org/) 
– FP with Clojure (http://mooc.cs.helsinki.fi/clojure)
FP Seminar at TTY
ClojuTRE 2014 
• Third annual Clojure seminar at Tampere 25.11.2014 
– Free beer, pizza  brackets 
– Follow @metosin for updates 
h)p://clojutre.org/2014/
Thanks. 
Tommi Reiman / @ikitommi 
http://www.metosin.fi

More Related Content

What's hot

Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
Anton Arhipov
 

What's hot (20)

Down the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM WonderlandDown the Rabbit Hole: An Adventure in JVM Wonderland
Down the Rabbit Hole: An Adventure in JVM Wonderland
 
JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015JRuby and Invokedynamic - Japan JUG 2015
JRuby and Invokedynamic - Japan JUG 2015
 
A Taste of Clojure
A Taste of ClojureA Taste of Clojure
A Taste of Clojure
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
JRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVMJRuby 9000 - Optimizing Above the JVM
JRuby 9000 - Optimizing Above the JVM
 
JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015JRuby 9000 - Taipei Ruby User's Group 2015
JRuby 9000 - Taipei Ruby User's Group 2015
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
iSoligorsk #3 2013
iSoligorsk #3 2013iSoligorsk #3 2013
iSoligorsk #3 2013
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waiting
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
 
JavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for DummiesJavaOne 2011 - JVM Bytecode for Dummies
JavaOne 2011 - JVM Bytecode for Dummies
 
Mito, a successor of Integral
Mito, a successor of IntegralMito, a successor of Integral
Mito, a successor of Integral
 
JRuby in Java Projects
JRuby in Java ProjectsJRuby in Java Projects
JRuby in Java Projects
 
Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012Mastering Java Bytecode - JAX.de 2012
Mastering Java Bytecode - JAX.de 2012
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Java to Scala: Why & How
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & How
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 

Similar to Clojure in real life 17.10.2014

Similar to Clojure in real life 17.10.2014 (20)

Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why ruby and rails
Why ruby and railsWhy ruby and rails
Why ruby and rails
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey Vasiliev
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemDownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)Modern Java Concurrency (OSCON 2012)
Modern Java Concurrency (OSCON 2012)
 
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane EcosystemDownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
DownTheRabbitHole.js – How to Stay Sane in an Insane Ecosystem
 
Go: What's Different ?
Go: What's Different ?Go: What's Different ?
Go: What's Different ?
 
Making Scala Faster: 3 Expert Tips For Busy Development Teams
Making Scala Faster: 3 Expert Tips For Busy Development TeamsMaking Scala Faster: 3 Expert Tips For Busy Development Teams
Making Scala Faster: 3 Expert Tips For Busy Development Teams
 
Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...Are High Level Programming Languages for Multicore and Safety Critical Conver...
Are High Level Programming Languages for Multicore and Safety Critical Conver...
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Performance and Abstractions
Performance and AbstractionsPerformance and Abstractions
Performance and Abstractions
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
01 java intro
01 java intro01 java intro
01 java intro
 
Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)Exploring Java Heap Dumps (Oracle Code One 2018)
Exploring Java Heap Dumps (Oracle Code One 2018)
 

More from Metosin Oy

More from Metosin Oy (19)

Navigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas SaariNavigating container technology for enhanced security by Niklas Saari
Navigating container technology for enhanced security by Niklas Saari
 
Where is Technical Debt?
Where is Technical Debt?Where is Technical Debt?
Where is Technical Debt?
 
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
Creating an experimental GraphQL formatter using Clojure, Instaparse, and Gra...
 
Serverless Clojure and ML prototyping: an experience report
Serverless Clojure and ML prototyping: an experience reportServerless Clojure and ML prototyping: an experience report
Serverless Clojure and ML prototyping: an experience report
 
Designing with malli
Designing with malliDesigning with malli
Designing with malli
 
Malli: inside data-driven schemas
Malli: inside data-driven schemasMalli: inside data-driven schemas
Malli: inside data-driven schemas
 
Naked Performance With Clojure
Naked Performance With ClojureNaked Performance With Clojure
Naked Performance With Clojure
 
Reitit - Clojure/North 2019
Reitit - Clojure/North 2019Reitit - Clojure/North 2019
Reitit - Clojure/North 2019
 
Fun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
Fun with errors? - Clojure Finland Meetup 26.3.2019 TampereFun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
Fun with errors? - Clojure Finland Meetup 26.3.2019 Tampere
 
Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)Clojutre Real Life (2012 ClojuTRE Retro Edition)
Clojutre Real Life (2012 ClojuTRE Retro Edition)
 
The Ancient Art of Data-Driven - reitit, the library -
The Ancient Art of Data-Driven - reitit, the library - The Ancient Art of Data-Driven - reitit, the library -
The Ancient Art of Data-Driven - reitit, the library -
 
Craft Beer & Clojure
Craft Beer & ClojureCraft Beer & Clojure
Craft Beer & Clojure
 
ClojuTRE2016 Opening slides
ClojuTRE2016 Opening slidesClojuTRE2016 Opening slides
ClojuTRE2016 Opening slides
 
Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016
Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016
Schema tools-and-trics-and-quick-intro-to-clojure-spec-22.6.2016
 
ClojuTRE - a (very) brief history
ClojuTRE - a (very) brief historyClojuTRE - a (very) brief history
ClojuTRE - a (very) brief history
 
Wieldy remote apis with Kekkonen - ClojureD 2016
Wieldy remote apis with Kekkonen - ClojureD 2016Wieldy remote apis with Kekkonen - ClojureD 2016
Wieldy remote apis with Kekkonen - ClojureD 2016
 
ClojuTRE2015: Kekkonen - making your Clojure web APIs more awesome
ClojuTRE2015: Kekkonen - making your Clojure web APIs more awesomeClojuTRE2015: Kekkonen - making your Clojure web APIs more awesome
ClojuTRE2015: Kekkonen - making your Clojure web APIs more awesome
 
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesomeEuroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
Euroclojure2014: Schema & Swagger - making your Clojure web APIs more awesome
 
Swaggered web apis in Clojure
Swaggered web apis in ClojureSwaggered web apis in Clojure
Swaggered web apis in Clojure
 

Recently uploaded

%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+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
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
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
 
+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...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
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 🔝✔️✔️
 
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
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
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 🔝✔️✔️
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

Clojure in real life 17.10.2014

  • 1. Clojure in Real Life Tommi Reiman / Metosin 17.10.2014
  • 2. Agenda • Clojure basics • In Real Life • Getting started • Q A
  • 4. Clojure • Clojure is a dynamic, functional, general purpose language – Compiled, strong (dynamic) typing • with optional static typing (core.typed) – Targets JVM, CLR and JavaScript – Immutable, persistent data structures – Interactive development (REPL) – Concurrency, software transactional memory core.async – Pragmatism over purism – Runtime polymorphism – A lisp, meta-programming with macros
  • 6. Syntax • Heterogeneous read-only data structures • All data literals stand for themselves, except Lists Symbols
  • 10. Macros • Macros are evaluated at compile-time (to generate code) • One can also (eval) code at runtime è Great tools for reducing boilerplate do concise DSLs unless?
  • 13. math speed / hiphip (array)!
  • 14. Concurrency • Immutable data structures, pure functions • State Identity separation via References – Vars, Refs, Atoms, Agents • futures, promises, delays • Libraries: Avout, Lamina, Pulsar, Onyx, (Akka) • core.async
  • 16. core.async • Library for channel-based async processing – Channels, go-blocks, transducers • Communicating sequential processes • https://golang.org/ • Both for threaded (JVM) non-threaded (JS) environments – http://swannodette.github.io/2013/08/02/100000-processes/
  • 17. core.async, example • Boiling Sous-Vide Eggs using Clojure's Transducers – http://blog.eikeland.se/2014/10/06/pid-transducer/?utm_content=buffer75806
  • 18. Didn’t cover • Protocols, Multimethods • Destructuring • Dynamic binding • Walkers • Records • Metadata
  • 19. Missed these too • core.match – pattern matching • core.typed – gradual (static) typing • core.logic – logic programming
  • 20. Ok, this is just another academic…
  • 22. Leiningen • Declarative build tool, uses Maven internally
  • 23. Testing • clojure.test (bundled), Midje (TDD/BDD), expectations • Clj-webdriver (browser tests) • test.check for generative tests • Leiningen plugins to generate (junit-)reports, run coverage etc.
  • 25. Editors • We (6) are currently using: – IDEA + Cursive – Eclipse + CCW – Vim + Fireplace – Emacs + Cider – LightTable • Not yet as good as the Java tools, but getting better every day
  • 26. REPL-driven workflow • Evaluate code as you go, instant feedback – Develop in Editor, evaluate in REPL – Ridiculously fast (single-pass) compiler • Massive boost in productivity • nRepl-servers • Browser-Repls
  • 27. Web stacks • Mostly micro-libraries on top of Ring – Request, Response, Adapters, Middlewares, Handlers – https://github.com/ring-clojure/ring • Packaged either: – standalone web servers (uberjar) – As Servlet Apps (and deploy as wars) • Some popular libs – Compojure (https://github.com/weavejester/compojure) – Liberator (http://clojure-liberator.github.io/liberator/) – Pedestal (https://github.com/pedestal/pedestal) • Lot’s of support libs (clostache, hiccup, enlive, …)
  • 31. Demo: a REST API • with Compojure-api Ring-Swagger
  • 33. Don’t trust the benchmark Go 211k h)p-­‐kit 137k Compojure 123k Scalatra 107k Play 98k Spring 42k h)p://www.techempower.com/benchmarks/#secKon=data-­‐r9hw=i7test=json
  • 34. Async web - Scala Clojure h)p://www.slideshare.net/colinlogaan/clojure-­‐at-­‐a-­‐post-­‐office-­‐36333973
  • 35. Persistence (of time) • Idiomatic wrappers on top of Java Libraries – RDB: Clojure.java.jdbc, Yesql, Korma – Monger (MongoDB), Welle (Riak), Cassaforte (Cassandra), Neocons (Neo4j), Carmine (Redis), … • Datomic Demo
  • 37. Utils • Use Java libraries or idiomatic clj-wrappers on top of them – clj-time, emailer, clj-ssh, timbre (logging) tons of other goodnesses
  • 38. Data formats • JSON maps 1:1 to Clojure – All core functions available, no need for external DSLs • XML, lazy parsers, zippers, selectors • Excel, use Apache POI directly • EDN, Transit • … Demo
  • 39. Clojurescript • Clojure compiled into JavaScript – No threads, some different implementation classes • Google Closure compiler • Browser-repls (http://clojurescript.net/) – Same dynamic development flow as with Clojure
  • 40. Demo: Flappy Bird h)ps://github.com/bhauman/flappy-­‐bird-­‐demo
  • 41. OM / Reagent • A ClojureScript interface to Facebook's React.js
  • 42.
  • 43. Game of Life h)p://clj-­‐me.cgrand.net/2011/08/19/conways-­‐game-­‐of-­‐life/
  • 44. Einstein / Zebra h)ps://github.com/swannode)e/logic-­‐tutorial
  • 46. So, do people use it?
  • 47. Thoughtworks Technology Radar 2014 Scala, adopt! Where’s my clojure?
  • 48.
  • 49. In Finland? • Zenrobotics – “the largest clojure codebase in the world”? • Metosin – Internally, for small large enterprises, Finnish Authorities (with friends) abroad – Training for others (Solita, Gofore, Futurice others) • Solita (with friends) • Others • (lots of startups)
  • 50. :stats (1.5y project, 5+ developers)
  • 51.
  • 52.
  • 53.
  • 54. Flushing the Brain • (Mutable) Objects à Immutable Data, (pure) functions, references • Design Patterns à mostly not needed (builder, strategy, visitor,…), new functional design patterns • Domain Driven Design à Anemic Domain Model is a Functional Domain Model • TDD à RDD (with tests) • Dependency Injection à Thought not needed, but still good for large apps (via Stuart Sierra’s Component-library, collecting app state into one place)
  • 55. Goods and Bads • Good – Simple and beautiful code – Awesome Development speed – Great friendly ecosystem (libs, people support) – The JVM Backup (can use Java anywhere, performance) – Clojurescript(!!!) – Extensibility (mini languages on top) • Bad – Startup time – CLJS Build tools (vs Gulp) – Refactoring in large projects (with current IDE support) – 10% times, missing the static type system
  • 56. I would use Clojure for… • Everything, replacing both Java Scala! • Just kidding, not for: – Android development (object apis, startup) à Scala/Java – Command line apps (slow startup) à whatever – Maybe not for distributed computing à Spark/Akka/Scala • But Clojure for mostly everything else.
  • 57. Clojure @ Metosin • Open source – Ring-Swagger Compojure-api (Swagger 2.0) – kekkonen.io (a snappy CQRS-lib) – Lein-simulflow • Community – Tech talks, seminars, dojos • Projects Training • Fun stuff
  • 59. Some resources • Books: – Clojure Programming – The Joy of Clojure, 2nd • Online – 4clojure (https://www.4clojure.com/) – ClojureDocs (http://clojuredocs.org/) – FP with Clojure (http://mooc.cs.helsinki.fi/clojure)
  • 61. ClojuTRE 2014 • Third annual Clojure seminar at Tampere 25.11.2014 – Free beer, pizza brackets – Follow @metosin for updates h)p://clojutre.org/2014/
  • 62. Thanks. Tommi Reiman / @ikitommi http://www.metosin.fi