Clojure
How, When, and Why?
nikola@plejic.com / @nikolaplejic
- dynamic, general-purpose PL
- compiled (JVM, CLR, JavaScript)
- dialect of Lisp
- focused on immutability
- excellent interop with target platforms
(defn add-two-numbers [x y] (+ x y))
The Idea of the Talk
- introduce the problem
- describe the context
- introduce features of Clojure
- see how the features helped
- Q&A
The Problem
- social-something software
- a LOT of HTTP queries to social APIs
- 25 accounts -> 20+ thousand
- inherently paralellizable problem
- that advantage? not used.
- obvious solution? parallelize!
The Context
- a PHP shop
- <understatement>PHP isn't suited for writing multithreaded software</understatement>
possible solutions in PHP
- multiple processes
- pthreads
- ...
Look Further!
Features
JVM Interop
...or: Mave-what?
- leiningen
- clojars.org
- no Clojure library for something?
- there's a Java library for that
(let [d (java.util.Date.)] (.getTime d))
Talking to the Outside World
The Tooling
- leiningen: not only dependency management
- (it handles builds as well)
- excellent editor support (Emacs, Vim, Sublime, ...)
Light Table
Ease of Deployment
- build a JAR/WAR
- (again, leiningen)
- push to the server & restart your app or app server
It's a Lisp!
- (parentheses!)
- code-as-data & macros
- very data-structure-oriented
It's Functional!
- immutable data structures
- higher-order functions
- Other Async/Multithreading Features:
- STM
- futures / promises
- core.async
The Community
- smart people
- lots of conferences
- EuroClojure 2015: Barcelona, June 25-26
- Cognitect
The Bad & The Ugly
- hard to hire
- parentheses & lisp-iness puts people off
- stacktraces (were) a bit tricky
Bottom Line
- interesting, exciting new language
- friendly, vibrant community
- different approach to certain problems
- very easy to get up & running (esp. with leiningen)
- easy to deploy (esp. if you're already running Java)
- good first step towards FP