Scala clojure techday_2011

  • 406 views
Uploaded on

IBM 2011 Brazilian Software Lab TechDay Presentation

IBM 2011 Brazilian Software Lab TechDay Presentation

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
406
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

Transcript

  • 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. Y = λf.(λx.f (x x)) (λx.f (x x))
  • 3. Y = λf.(λx.f (x x)) (λx.f (x x))
  • 4. What is functional programming about?
  • 5. Lambda calculus (a.k.a λ-calculus) function definition function application recursion
  • 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. FP has been around since the 1950’s Why it is becoming more important now?
  • 8. FP has been around since the 1950’s Why it is becoming more important now?
  • 9. FP has been around since the 1950’s Why it is becoming more important now? Why should I care?
  • 10. Because of them...
  • 11. Because of them...... the multi-core processors
  • 12. Because of them...... the multi-core processors (also, to become a smarter developer!)
  • 13. On the other side...
  • 14. On the other side... The JVM is cool!
  • 15. JVM -> Java LanguageHuge investment already on the JVM(libraries, middleware, performance, GC,remote communication, etc..)JVM executes byte-code
  • 16. The question is:
  • 17. The question is: Why not create new (functional) languages on top of the JVM?
  • 18. (not Closure)
  • 19. Clojure has...
  • 20. Clojure has...... tight integration with the JVM and Java
  • 21. Clojure has...... tight integration with the JVM and Java... compilation for performance
  • 22. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation
  • 23. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-efficient immutable collections
  • 24. Clojure has...... tight integration with the JVM and Java... compilation for performance... dynamic evaluation... memory-efficient immutable collections... lazy sequences
  • 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. Clojure is a LISP
  • 27. Clojure is a LISP (Lots of (Irritating(Stupid (Parentheses))))
  • 28. Clojure is a LISP (Lots of (Irritating(Stupid (Parentheses)))) a.k.a. List Processing
  • 29. LISP
  • 30. LISPHomoiconicity - code is data
  • 31. LISPHomoiconicity - code is dataMacros
  • 32. LISPHomoiconicity - code is dataMacrosMultiple dispatch (multi-methods)
  • 33. Syntax OperandsOperator (arguments)(str "Hello" "World") Expression delimiters
  • 34. Syntax["red" "green" "blue"] Array{:color "blue" :length 2} Map:color Keyword#(even? %) Anonymous function
  • 35. Higher-Order Functions
  • 36. Efficient Immutable Collections
  • 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. Java Integration(def now (new java.util.Date))(def now (java.util.Date.))(. now getTime)(doto (JFrame.) (. add (JLabel. "Hello, Clojure!")) (. pack) (. show))
  • 39. sample
  • 40. ScalaFastFunctionalExpressiveStatically typed (with type inference)Concurrent
  • 41. every value is an objectvals / varstraitscompanion objectscurryingclosures / high order functionspattern matching / case classesXML literalsLazy evaluation, and much more...
  • 42. sample
  • 43. To sum up...
  • 44. We cannot choose our problems.... .... but we can choose our tools.It is our responsibility to figure out the “right” tool.
  • 45. Even if you cant usethese languages in your day job yet, learning them will make you a better programmer!
  • 46. Referenceshttp://clojure.org/http://www.scala-lang.org/