Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM,...

27
Clojure: What Just Happened? Rich Hickey

Transcript of Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM,...

Page 1: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Clojure:What Just Happened?

Rich Hickey

Page 2: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Clojure is Becoming Popular

• Popular*

• Functional

• Lisp

• Not terribly novel

Page 3: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

How Popular?• 8000+ member mailing list

82,000+ messages

• 700+ on IRC

• #2 (behind Scala) non-Java JVM server lang

• Many companies use in production

Startups to Fortune 50

• > Dozen books, several 2nd editions

• 3 Clojure conferences per year

Page 4: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Github New Repos 2013 (thus far)

Rank Lang New repos

15 Scala 6918

16 Go 6884

17 Prolog 5829

18 Clojure 4904

19 Haskell 4681

20 Lua 4048

Page 5: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Context• JVM

• PHP, Python, Perl, Ruby

broke C-lineage stranglehold

demonstrated dynamic lang agility

• Paul Graham’s essays

• Crushing complexity of stateful OO

• JSON, XML

Page 6: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Right Place, Right Time?

• In fall 2007 when announced, no one had heard of me nor Clojure

• 18,000 hits the first day

Page 7: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Survey 2012 - GrowthStopped

1%

< 1 year43%

1 year18%

2 years18%

3 years14%

4+years6%

1,372 respondents

http://cemerick.com/2012/08/06/results-of-the-2012-state-of-clojure-survey/

Page 8: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

From Where?

Java

Ruby

Python

C#

Erlang/Scala/Haskell

Other

0 10 20 30 40

Page 9: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Why?

Page 10: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Practical

• Target - use it wherever you could use Java

both reach and performance

• Tool, for professional programmers

hobbyists welcome

• General purpose programming

Page 11: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Small

• A basic Lisp evaluation model

• No continuations, condition systems etc

Page 12: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Simple

• Few, orthogonal axes

• Functions, data, state model, evaluation model, macros etc

Page 13: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

FP Benefits, Distilled• Pure functions + immutable data

• Made practical and idiomatic

• Efficient persistent data structures the default

• Functional core library

• No mutable local variables

• Clearly separate state constructs

Page 14: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Opinionated

• Fewer choices

• Set of decisions made and encoded

• Everything works together

Page 15: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Eschews Types for Information

• Simple data - lists, vectors, maps, sets

• Associative collections in lieu of objects

• First-class names (keywords)

Page 16: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Minimal Type-Specific Code

• just generic map-manipulation code

• therefore, much less code

• more reuse

• better interop and libs

• facilitates systems building

• less compiler help

Page 17: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Runtime Polymorphic

• People coming from OO understand and expect this

• Abstractions for everything (even invocation)

• Polymorphism constructs are ‘open’

Page 18: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Concurrency?

• Not so much

• Part of initial story

• Has to be there

• but rarely needed

Page 19: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Hosted

• Dominant hosts (JVM, JS)

• Great interop

• Libraries out of the gate

• No migration pain

• Easy to sneak in

“just another library”

Page 20: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Lisp

• Still has appeal

• Small core, rest is libs

• Runtime redef, code loading, macros

• Code-as-data, read/print, REPL

• but enhancements matter

fp, collections, syntax, abstractions

Page 21: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Permissive

• “Consenting adults” language

• Support the right thing

• vs disallow the wrong

Page 22: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Support and Evangelism

• 3 years x 10 hours/day

Mailing list and IRC

• Lots of talks and travel

Page 23: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Stability

• All programs from first book (2009) still work

• Always a high priority

Page 24: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

The Blub Paradox?

• People don’t know what they are missing?

• They know what they are getting

• Simpler and more robust programs

• High productivity

• Resulting systems work, perform well, and are flexible

• Clojure is an effective tool

Page 25: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Biggest Wins

Functional

REPL

Platform/JVM

Immutability

Productivity

Macros

Concurrency

0 22.5 45 67.5 90

Page 26: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Gateway Drug?

Scala

Haskell

Python

Common Lisp

Ruby

Java

Scheme

Erlang

0 10 20 30 40

If Clojure disappeared, then what?

“too depressing to contemplate”

Page 27: Clojure: What Just Happened? · • Pure functions + immutable data ... • Dominant hosts (JVM, JS) ... Immutability Productivity Macros Concurrency 0 22.5 45 67.5 90. Gateway Drug?

Thanks!