istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear...

30
Clojure Introduction @codemomentum sebula.com

Transcript of istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear...

Page 1: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction@ c o d e m o m e n t u m

!s e b u l a . c o m

Page 2: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Motivation

• Software Development is about taking things apart.

• Clojure is a simple and elegant language.“Simplicity is a pre-requisite for reliability” (Dijkstra)

• Clojure demands that you raise your game, and pays you back for doing so.

Page 3: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Why Clojure?

• Extremely expressive language

• First-class functions

• Awesome Java Interop abilities

• Power of lisp (macros, function composition)

• FUNctional

Page 4: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Why Lisp?

• Little Syntax to Learn

• Say a lot more with less code, fewer lines, fewer bugs

• Bend your language to the problem, not the other way around

• Code as Data

Page 5: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Why Lisp?

When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying: "I tried one of those bananas, which you say are so delicious. The white part was ok, but the yellow part was very tough and tasted awful.

Paul Graham

Page 6: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Functional Programming

• OOP makes code understandable by encapsulating moving parts

• FP makes code understandable by minimizing moving parts

!• Better fit for concurrency and multicore architectures

Page 7: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Agility!

• Architectural agility is the agility you get from building a system that is fundamentally simple.

• Simplicity enables change, it’s the primary source of real agility.

• If you’re dragging an elephant around you’re never going to be agile

* “Simple Made Easy” by Rich Hickey

Page 8: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Simple Use Case

CommandExecutor.java

Executes the command that is described in the “command description”

Result and Document are wrappers around java.util.Map

Step1: Design

Step2: Implement & TestHttpCommandExecutor.java JmxCommandExecutor.java JmsCommandExecutor.java

Step3: Integrate

CommandExecutorService.java

ExecutorRegistry.java

Page 9: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Simple Use CaseStep3: Integrate

DelegatingCommandExecutorService.java

SimpleExecutorRegistry.java

Page 10: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Simple Use CaseStep4: In Action

someApplicationContext.xml

Page 11: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

This is brilliant if you are charging by the hour

Page 12: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Simple Use Case - ClojureDelegator

Code for one of the handlers (Bonus)

Page 13: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

What Clojure Looks Like

int function ( ) { return 5; }

( fn [ ] 5 )

1+1; (+ 1 1)

System.out.println(“Hello World!”); (println “Hello World!”)

Page 14: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Language Primitives

Boolean true, falseCharacter \aKeyword :a, :b

List (1 2 3), (println x)Map {:marka "Bmw", :model “320d”, :renk “mavi”}Nil nil

Number 1, 4.5Set #{“a” “b” “c”}

String “Ola!”Symbol user/foo, java.lang.StringVector [1 2 3]

Page 15: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Special FormsEvery form not handled specially by a special form or macro is considered by the compiler to be an expression, which is evaluated to yield a value.

def (def symbol init?)

if (if test then else?)

do (do exprs*)

let (let [bindings* ] exprs*)

quote (quote form)

var (var symbol)

fn (fn name? [params* ] exprs*)

loop (loop [bindings* ] exprs*)

recur (recur exprs*)

try/catch/throw (try expr* catch-clause* finally-clause?)

Page 16: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Functions

Page 17: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Collections

{ } Map {“a” 1 “b” 2}

#{ } Set {“a” “b” “c”}

‘( ) List ‘(1 2 3)

[ ] Vector [“a” “b” “c”]

The trick is to efficiently use primitive data structures and library functions

Page 18: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Examples

=>(doc map)…… !=>(map inc [3 4 5]) (4 5 6) !=> (doc reduce) ……. !=> (reduce + [3 4 5]) 12 !

Page 19: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Examples=>(doc filter)…… !=> (filter even? [1 2 3 4]) (2 4) !=> (doc remove) …… !=> (remove nil? [1 nil 2 nil]) (1 2) !!!

=>(doc reductions)…… !=> (reductions + [1 2 3 4]) (1 3 6 10) !=> (doc remove) …… !=> (remove nil? [1 nil 2 nil]) (1 2) !!!

Page 20: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure Introduction - Key Concepts

• Leiningen (Clojure Build Tool) !

• Repl !

• Emacs !

• CounterClockwise (Eclipse Plugin) !

• La Clojure / Cursive (Idea Plugins) !

• JVM tools

Page 21: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Who is Using Clojure

• Nokia Maps • Twitter • Factual • Lumosity • YieldBot • USwitch • Climate • Akamai • Citi • Nugg • Prismatic • Netflix

Page 22: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure @Sebula

• Distributed Crawler that supports Http, MongoDB, JDBC

RedisStorm Spout

Storm Bolts

Manager

HTTPMongoDB JDBC

Storm Bolts

Elastic Search

Page 23: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure @Sebula• Unique Delay queue with Carmine (Redis Library)

Page 24: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure @Sebula

• Quartize (Quartz Library)

Page 25: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure @Sebula

• Search Analytics • Flume, Cassandra, Cascading, Cascalog

Elasticsearch Cluster

Flume Collector (Clojure)

Elasticsearch Cluster

Flume Collector (Clojure) Cassandra

Rest

(Cascalog & Clojure)

Dashboard

Page 26: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure @Sebula

• Rcmmndr: Hadoop & Cassandra Integration

Http Collector (Clojure)

Http Collector (Clojure) Cassandra

Mahout Manager (Clojure)

Rest Backend

Rest Backend

Page 27: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Clojure In Depth

• Collections & Data Structures • Destructuring • State & Concurrency & Parallelism • Macros • Protocols & Datatypes • MultiMethods • Java Interoperability

Page 28: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Talks

• Simple Made Easy by Rich Hickey !

• Narcissistic Design - Stuart Halloway

Page 29: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Books

• Land of Lisp • Clojure Programming • Programming Clojure

Page 30: istanbul hackers clojureistanbulcoders.org/assets/meetups/2013-11-07... · Why Lisp? When I hear people complain about Lisp's parentheses, it sounds to my ears like someone saying:

Resources• Programming Clojure • ClojureWerkz Clojure Workshop: http://clojureworkshop.com/ • Working with Legacy Code • clojureist.com • IstanbulCoders.org • [email protected]