13

Click here to load reader

Why Functional Programming and Clojure - LightningTalk

Embed Size (px)

DESCRIPTION

Lightning talk - why functional programming is worth learning and using and why Clojure is a good functional language to start with.

Citation preview

Page 1: Why Functional Programming and Clojure - LightningTalk

(why (and :functional-programming :clojure) :matters)

Page 2: Why Functional Programming and Clojure - LightningTalk

Why Should You Listen?

To learn ● Why FP useful for us● Why to learn a "useless" side language● Why Clojure

Page 3: Why Functional Programming and Clojure - LightningTalk

Why functional programming matters?

Proposals?

Page 4: Why Functional Programming and Clojure - LightningTalk

Functional programming: What, why?

● Simplicity: Limit state, side-effects○ Referential transparency○ Immutable persistent data structures○ STM, agents etc.○ => concurrency

● Higher abstractions, including○ HOF: More reuse - compose behavior○ Multimethods: Dispatch on any argument(s)

● Language maintains state (lex. scope, loop)● Generic operations on generic data structs● Key design question: What it does?

Page 5: Why Functional Programming and Clojure - LightningTalk

You may ask

Why hasn't FP taken the world over yet?

Page 6: Why Functional Programming and Clojure - LightningTalk

But then we could also ask

Why became OOP, available since Simula 67, only popular in 90s?

(Even though Smalltalk is more OO than Java and C++ and available since '81.)

It takes time, money, opportunity, optimization, and luck for concepts to take hold.

Page 7: Why Functional Programming and Clojure - LightningTalk

Why Clojure?

● It's different○ Functional - new paradigm, back-port learnings

● It's Lisp - the most powerful language ever○ Macros - infinite abstraction○ Write the language fitting the domain first

● It runs on JVM○ Reuse, interoperab., mature and available platform

● Designed for concurrency

Page 8: Why Functional Programming and Clojure - LightningTalk

Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.

Eric S. Raymond, "How to Become a Hacker"

Page 9: Why Functional Programming and Clojure - LightningTalk

Clojure: Basic Facts

● Functional language for JVM (and .net, JS)● Dynamically-typed● Good Java interoperability● 2006 started, 2009 v1.0, 2011 v1.3● A Lisp ('58) dialect● Emphasis on simplicity● Designed for concurrency

○ STM, agents, immutability, ...● Flexible, extensible● Support for objects● Code <=> data

Page 10: Why Functional Programming and Clojure - LightningTalk

Clojure Syntax

(function arg1 arg2 ...)(list 1 2 3 4 5)(+ 1 2 3)(def square (fn [x] (* x x)))

Lists - and that's all!● Well, nearly - also 13 'special forms' (def, if,

let, fn, try, ..)● Few data types: '(), [], #{}, {}● Literals: 1, "str", :key, symbol

Page 11: Why Functional Programming and Clojure - LightningTalk

Example: SQL

(defentity person) (dry-run (select person (where {:name "Bodil" :age [> 18]}) (order :name :ASC)))

By Bodil Stokke, github.com/bodil

Page 12: Why Functional Programming and Clojure - LightningTalk

Thank you!

Page 13: Why Functional Programming and Clojure - LightningTalk

Refs

● http://stackoverflow.com/questions/1786969/pitfalls-disadvantages-of-functional-programming

● http://c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming

● http://c2.com/cgi/wiki?OoVsFunctional● http://c2.com/cgi/wiki?FpVsOo● http://c2.com/cgi/wiki?FunctionalModeling● http://c2.com/cgi/wiki?

ArchitectureAndFunctionalProgramming● http://clojure.org/rationale