Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Functional Programming          on the JVM with          Scala and Clojure            What they are and why you should car...
Y = λf.(λx.f (x x)) (λx.f (x x))
Y = λf.(λx.f (x x)) (λx.f (x x))
What is functional programming            about?
Lambda calculus (a.k.a λ-calculus)  function definition  function application  recursion
Referential Integrity  Avoids state and mutable dataHigher-Order functions:  Functions can receive and return other  funct...
FP has been around since the 1950’s   Why it is becoming more important now?
FP has been around since the 1950’s   Why it is becoming more important now?
FP has been around since the 1950’s   Why it is becoming more important now?                Why should I care?
Because of them...
Because of them...... the multi-core processors
Because of them...... the multi-core processors    (also, to become a smarter             developer!)
On the other side...
On the other side... The JVM is cool!
JVM -> Java LanguageHuge investment already on the JVM(libraries, middleware, performance, GC,remote communication, etc..)...
The question is:
The question is:    Why not create new (functional)     languages on top of the JVM?
(not Closure)
Clojure has...
Clojure has...... tight integration with the JVM and Java
Clojure has...... tight integration with the JVM and Java... compilation for performance
Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation
Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-e...
Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-e...
Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-e...
Clojure is a LISP
Clojure is a LISP  (Lots of (Irritating(Stupid (Parentheses))))
Clojure is a LISP  (Lots of (Irritating(Stupid (Parentheses))))    a.k.a. List Processing
LISP
LISPHomoiconicity - code is data
LISPHomoiconicity - code is dataMacros
LISPHomoiconicity - code is dataMacrosMultiple dispatch (multi-methods)
Syntax              OperandsOperator     (arguments)(str "Hello" "World")           Expression           delimiters
Syntax["red" "green" "blue"]               Array{:color "blue" :length 2}              Map:color                          ...
Higher-Order Functions
Efficient Immutable    Collections
Lazy Sequencesimport java.util.HashMap;import java.util.Map;public class ColorMapper {	   private static String[] COLORS =...
Java Integration(def now (new java.util.Date))(def now (java.util.Date.))(. now getTime)(doto (JFrame.)  (. add (JLabel. "...
sample
ScalaFastFunctionalExpressiveStatically typed (with type inference)Concurrent
every value is an objectvals / varstraitscompanion objectscurryingclosures / high order functionspattern matching / case c...
sample
To sum up...
We cannot choose our problems....  .... but we can choose our tools.It is our responsibility to figure out           the “r...
Even if you cant usethese languages in your  day job yet, learning them will make you a  better programmer!
Referenceshttp://clojure.org/http://www.scala-lang.org/
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Scala clojure techday_2011
Upcoming SlideShare
Loading in …5
×

Scala clojure techday_2011

IBM 2011 Brazilian Software Lab TechDay Presentation

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

Scala clojure techday_2011

  1. 1. Functional Programming on the JVM with Scala and Clojure What they are and why you should care Cristiano Breuel Thadeu RussoAdvisory Software Engineer Advisory Software Engineer (cbreuel@br.ibm.com) (thadeurc@br.ibm.com)
  2. 2. Y = λf.(λx.f (x x)) (λx.f (x x))
  3. 3. Y = λf.(λx.f (x x)) (λx.f (x x))
  4. 4. What is functional programming about?
  5. 5. Lambda calculus (a.k.a λ-calculus) function definition function application recursion
  6. 6. Referential Integrity Avoids state and mutable dataHigher-Order functions: Functions can receive and return other functionsLazy Evaluation: Evaluate an expression only when necessary
  7. 7. FP has been around since the 1950’s Why it is becoming more important now?
  8. 8. FP has been around since the 1950’s Why it is becoming more important now?
  9. 9. FP has been around since the 1950’s Why it is becoming more important now? Why should I care?
  10. 10. Because of them...
  11. 11. Because of them...... the multi-core processors
  12. 12. Because of them...... the multi-core processors (also, to become a smarter developer!)
  13. 13. On the other side...
  14. 14. On the other side... The JVM is cool!
  15. 15. JVM -> Java LanguageHuge investment already on the JVM(libraries, middleware, performance, GC,remote communication, etc..)JVM executes byte-code
  16. 16. The question is:
  17. 17. The question is: Why not create new (functional) languages on top of the JVM?
  18. 18. (not Closure)
  19. 19. Clojure has...
  20. 20. Clojure has...... tight integration with the JVM and Java
  21. 21. Clojure has...... tight integration with the JVM and Java... compilation for performance
  22. 22. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation
  23. 23. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-efficient immutable collections
  24. 24. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-efficient immutable collections... lazy sequences
  25. 25. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-efficient immutable collections... lazy sequences... primitives for concurrency (STM, agents)
  26. 26. Clojure is a LISP
  27. 27. Clojure is a LISP (Lots of (Irritating(Stupid (Parentheses))))
  28. 28. Clojure is a LISP (Lots of (Irritating(Stupid (Parentheses)))) a.k.a. List Processing
  29. 29. LISP
  30. 30. LISPHomoiconicity - code is data
  31. 31. LISPHomoiconicity - code is dataMacros
  32. 32. LISPHomoiconicity - code is dataMacrosMultiple dispatch (multi-methods)
  33. 33. Syntax OperandsOperator (arguments)(str "Hello" "World") Expression delimiters
  34. 34. Syntax["red" "green" "blue"] Array{:color "blue" :length 2} Map:color Keyword#(even? %) Anonymous function
  35. 35. Higher-Order Functions
  36. 36. Efficient Immutable Collections
  37. 37. Lazy Sequencesimport java.util.HashMap;import java.util.Map;public class ColorMapper { private static String[] COLORS = {"white", "blue"}; public static Map<String, String> mapLineColors(String[] values) { Map<String, String> retVal = new HashMap<String, String>(); int i = 0; for (String value: values) { retVal.put(value, COLORS[i % COLORS.length]); i++; } return retVal; } public static void main(String[] args) { String[] values = {"Clojure", "Java", "Scala", "Visual Basic"}; System.out.println(mapLineColors(values)); } }
  38. 38. Java Integration(def now (new java.util.Date))(def now (java.util.Date.))(. now getTime)(doto (JFrame.) (. add (JLabel. "Hello, Clojure!")) (. pack) (. show))
  39. 39. sample
  40. 40. ScalaFastFunctionalExpressiveStatically typed (with type inference)Concurrent
  41. 41. every value is an objectvals / varstraitscompanion objectscurryingclosures / high order functionspattern matching / case classesXML literalsLazy evaluation, and much more...
  42. 42. sample
  43. 43. To sum up...
  44. 44. We cannot choose our problems.... .... but we can choose our tools.It is our responsibility to figure out the “right” tool.
  45. 45. Even if you cant usethese languages in your day job yet, learning them will make you a better programmer!
  46. 46. Referenceshttp://clojure.org/http://www.scala-lang.org/

×