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

841 views

Published on

IBM 2011 Brazilian Software Lab TechDay Presentation

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
841
On SlideShare
0
From Embeds
0
Number of Embeds
40
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • Thadeu e Cristiano: Apresentação dos palestrantes\n
  • Thadeu: Apenas assustar o pessoal - dizer que precisamos antes entender o combinador Y\n
  • Thadeu: slide apenas de passagem, sem muitos comentarios.\n
  • Thadeu: basicamente ler o slide.\n
  • Thadeu: da wikipedia: is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.\nenfatiza a aplicacao de funcoes ao contrario da mudanca de estado, como eh feito em linguagens interativas\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: Parar em visual F# - lembrar de chamar atenção para sql e spredsheets\n
  • Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo não academico\n
  • Thadeu: intrigar a plateia - perguntar se alguem sabe e nao deixar responder - comentar que as linguagens sempre foram vistar como muito teoricas para o mundo não academico\n
  • Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  • Thadeu: discutir um pouco os detalhes tecnicos do impacto\n
  • Thadeu passa para Cristiano.\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • Cristiano:\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Thadeu: Comentar cada um dos itens acima (dizer tbm q eh menos verborragica que java) - veremos exemplo\n
  • Thadeu: ir para o repl e fazer alguns exemplos destes caras\nval\nfunction as objects\nreduceLeft - usar as chaves e fazer o currying\n\n\nsobre a parte de lazy - comentar que nao existem lazy collections assim como em haskell ou closure, porem\nda para criar metodos que fazer conversoes de modo lazy (usando iteradores)\n
  • Thadeu: Converter codigo java para scala\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 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/

    ×