Click here to load reader
Upload
jakub-holy
View
626
Download
0
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
(why (and :functional-programming :clojure) :matters)
Why Should You Listen?
To learn ● Why FP useful for us● Why to learn a "useless" side language● Why Clojure
Why functional programming matters?
Proposals?
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?
You may ask
Why hasn't FP taken the world over yet?
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.
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
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"
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
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
Example: SQL
(defentity person) (dry-run (select person (where {:name "Bodil" :age [> 18]}) (order :name :ASC)))
By Bodil Stokke, github.com/bodil
Thank you!
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