This is a talk I gave at CFCAMP 2012 in Munich. It's an introduction to Clojure for CFML developers and how to leverage Clojure from a CFML developer's point of view.
There are various examples and demo code that's not on the slides, contact me if you're interested in it.
4. Kai Koenig
Working with CFML since 1999
Developing for mobile since 2003
Recovering Flex developer being sucked into JS deeper and deeper
Recently rediscovered Functional Programming
bloginblack.de
2ddu.com
twitter.com/agentK
6. 1. Why Functional Programming?
2. Why Clojure?
3. Some demos and (probably failing :-) live coding in
the Clojure REPL
4. A quick look at Clojure and CFML integration
9. Who of you has a
traditional, old-school
CompSci or Maths
degree?
10. The ones among you who answered with “yes”
probably have dabbled with either of:
ML
Scheme
Haskell
Lisp
At some point during their degree.
11. I did. Haskell and ML *
* Kind of confused me, I couldn’t see the point and we had Java anyway - which was
much more awesome & could do OO & was the hipster language of the day ** &
you could write AWT and Swing apps and just because.
** The day was 1996; Java was at version 1.0.2; and I was in my first year of my
CompSci and Maths degree
12. What is it?
A programming paradigm based on functions as first-
class citizens and a theoretical concept called “Lamba
Calculus”.
Depending on the FP language you’re looking at,
features might vary, but there are a few common
themes in functional programming.
14. Function that can take other functions as arguments or
return them as results (e.g. d/dx - differential operator
in calculus to return the derivative of a function).
Higher-order vs. first-class: just a subtle difference -
previous is a mathematical concept, latter is a CompSci
term.
16. Functions without I/O and memory side effects.
1. result is constant with respect to the parameter list
2. function call can be performed in parallel, they can’t
interfere with each other; thread safety
3. compiler has much more freedom in the evaluation
strategy of expressions provided the whole language is
side effect-free.
18. In functional languages, iteration (loops) are pretty
much exclusively done via recursion.
Recursion functions invoke themselves all over again.
Intermediate state is kept on a stack.
21. But hang on. The world is full of “state”.
And side-effects.
I mean - WTF?
22. State can (and has to) be simulated in FP.
Different languages use different concepts that still keep
the functional paradigm pure.
Monads (Haskell)
State passing style (A bunch of other FP languages)
Managed references (Clojure)
27. -- describe an infinite list based on the recurrence
relation for Fibonacci numbers
fibRecurrence first second = first : fibRecurrence
second (first + second)
-- describe fibonacci list as fibRecurrence with initial
values 0 and 1
fibonacci = fibRecurrence 0 1
-- describe action to print the 10th element of the
fibonacci list
main = print (fibonacci !! 10)
51. One idea: Model in MVC apps
Why? Because Clojure allows you to express business
logic and model data extremely efficiently.
Or: when you need to be able to run certain code in a
highly parallelised environment.
53. Get in touch
Twitter: @AgentK
Blog: http://bloginblack.de
Podcast (2 Developers Down Under): http://2ddu.com
About me: http://about.me/agentk
Editor's Notes
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
The functional paradigm has its root in the Lambda calculus, a method for notations and manipulation of mathematical functions introduced by Alonso Church around 1930.Lambda calculus was then rediscovered as a versatile programming tool by McCarthy in 1958 when Lisp was introduced as a programming language able to deal with mathematical notation.\n\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Moore’s law recently failed on one of its axis. CPU speed is not doubling or tripling every year anymore. It used to be the case in the late ’90. But the demand of computing power is growing as usual.\nHardware manufacturer resorted to other means to increase power, such as transistor density. Right now is not uncommon to see cheap laptops sold with 4 cpu cores out of the box. Change on chip density requires a change in software scalability. Software must be written for concurrency to take advantage of multi-core architectures.\n\n
\n
Serious question: Who feels confident that they know how to PROPERLY use CFLOCK\n
\n
What about Clojure in specific? Clojure is a relatively young programming language based on Lisp but running on the JVM.\nIt comes out from the frustration of Rich Hickey developing highly concurrent systems as a Java and .NET consultant.\nRich Hickey developed dotLisp for the .NET environment before Clojure.\nHe spent then 2.5 years designing and implementing Clojure. Clojure was officially announced in 2007.\n\n
Learning another language stimulates your brain\nIt’s interesting\nIt’s a new community\n\nFunny enough - Adobe kicking Flex in the butt stimulated this\n\n