Who's More Functional: Kotlin, Groovy, Scala, or Java?

9,469 views

Published on

Published in: Technology

Who's More Functional: Kotlin, Groovy, Scala, or Java?

  1. 1. Whos More Functional Groovy, Kotlin, Scala or Java? Andrey BreslavWednesday, October 3, 12 1
  2. 2. About Me • Project lead of Kotlin ➡ at JetBrains since 2010 Andrey Breslav • EG member of JSR-335 ➡ Project Lambda 2Wednesday, October 3, 12 2
  3. 3. Prologue 3Wednesday, October 3, 12 3
  4. 4. Prologue – Dad (or Mom), is Java a functional language? 3Wednesday, October 3, 12 3
  5. 5. Prologue – Dad (or Mom), is Java a functional language? – Dont you know your dad from your mom?! 3Wednesday, October 3, 12 3
  6. 6. What is FP like?Wednesday, October 3, 12 4
  7. 7. Alonzo Church 𝛌 1936 5Wednesday, October 3, 12 5
  8. 8. Alonzo Church 𝛌 1936 1946 5Wednesday, October 3, 12 5
  9. 9. Alonzo Church 𝛌 1936 1946 5Wednesday, October 3, 12 5
  10. 10. Alonzo Church 𝛌 1936 1946 1956 5Wednesday, October 3, 12 5
  11. 11. John Backus Alonzo Church 𝛌 1936 1946 1956 5Wednesday, October 3, 12 5
  12. 12. Can Programming be Liberated from the von Neumann Style? John Backus Alonzo Church 𝛌 1936 1946 1956 1976 5Wednesday, October 3, 12 5
  13. 13. 6Wednesday, October 3, 12 6
  14. 14. – Dad, whats good about FP? 6Wednesday, October 3, 12 6
  15. 15. – Dad, whats good about FP? – It makes you look smart 6Wednesday, October 3, 12 6
  16. 16. – Dad, whats good about FP? – It makes you look smart – Like wearing glasses? 6Wednesday, October 3, 12 6
  17. 17. Effects (Mutability) 𝛌 John von Neumann Inputs commands State VS f(g(x), y) Outputs 7Wednesday, October 3, 12 7
  18. 18. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Leonardo FibonacciWednesday, October 3, 12 8
  19. 19. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Leonardo FibonacciWednesday, October 3, 12 8
  20. 20. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Are you functional? Kotlin V Groovy V Leonardo Fibonacci Scala V Java 8 V RecursionWednesday, October 3, 12 8
  21. 21. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Leonardo FibonacciWednesday, October 3, 12 8
  22. 22. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Leonardo FibonacciWednesday, October 3, 12 8
  23. 23. 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Leonardo Fibonacci commands StateWednesday, October 3, 12 9
  24. 24. Effect-Free 10Wednesday, October 3, 12 10
  25. 25. Effect-Free 10Wednesday, October 3, 12 10
  26. 26. Effect-Free – Dad, how do I 10Wednesday, October 3, 12 10
  27. 27. Effect-Free – Dad, how do I - print("Hello")? 10Wednesday, October 3, 12 10
  28. 28. Effect-Free – Dad, how do I - print("Hello")? - write to a file? 10Wednesday, October 3, 12 10
  29. 29. Effect-Free – Dad, how do I - print("Hello")? - write to a file? - do both? 10Wednesday, October 3, 12 10
  30. 30. Effect-Free Are you functional? Kotlin V X – Dad, how do I - print("Hello")? Groovy V X - write to a file? Scala V X - do both? Java 8 V X Recursion Pure 10Wednesday, October 3, 12 10
  31. 31. Summary • FP makes things simpler • Sometimes at a huge price • Our languages are not purely functional 11Wednesday, October 3, 12 11
  32. 32. Higher Order FP brings order :)Wednesday, October 3, 12 12
  33. 33. FibonacciTest 13Wednesday, October 3, 12 13
  34. 34. FibonacciTest – How do I test both implementations? 13Wednesday, October 3, 12 13
  35. 35. test(f) 14Wednesday, October 3, 12 14
  36. 36. test(f) Are you functional? Kotlin V X V Groovy V X V Scala V X V Java 8 V X V Recursion Pure HO 14Wednesday, October 3, 12 14
  37. 37. GoF and FP rd er r-O n he io ig ct H n Strategy = Fu Command Observer Abstract State Visitor Factory 15Wednesday, October 3, 12 15
  38. 38. Internal Iteration 16Wednesday, October 3, 12 16
  39. 39. Internal Iteration users: ArrayList user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  40. 40. Internal Iteration users: ArrayList users: ParallelCollection user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  41. 41. Internal Iteration users: ArrayList users: ParallelCollection user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  42. 42. Internal Iteration users: ArrayList users: ParallelCollection user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  43. 43. Internal Iteration users: ArrayList users: ParallelCollection user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  44. 44. Internal Iteration users: ArrayList users: ParallelCollection user 1 Hello user 2 Hello user 3 Hello user 4 Hello 16Wednesday, October 3, 12 16
  45. 45. Summary • Good old callbacks/strategies • Very important abstraction 17Wednesday, October 3, 12 17
  46. 46. ADT What is your "A" for?Wednesday, October 3, 12 18
  47. 47. Example: Messages Server Client 19Wednesday, October 3, 12 19
  48. 48. Example: Messages Server Client search for "lambda" 19Wednesday, October 3, 12 19
  49. 49. Example: Messages Server Client search for "lambda" exact match at ... 19Wednesday, October 3, 12 19
  50. 50. Example: Messages Server Client search for "lambda" exact match at ... similarity at ... 19Wednesday, October 3, 12 19
  51. 51. Example: Messages Server Client search for "lambda" exact match at ... similarity at ... message ::= search for term | exact item | similar item 19Wednesday, October 3, 12 19
  52. 52. ADT Abstract Algebraic data type data type ~I ~D nte ata rfa cla ce ss 20Wednesday, October 3, 12 20
  53. 53. Are you functional? ADT Kotlin V X V V Groovy V X V V Abstract Algebraic Scala typeV data X V data type V ~I V ~D Java 8 nt X V V ata erf cla ace ss Recursion Pure HO ADT 20Wednesday, October 3, 12 20
  54. 54. ADT in Kotlin 21Wednesday, October 3, 12 21
  55. 55. Utilization You may have your cake, but can you eat it too?Wednesday, October 3, 12 22
  56. 56. Up to 5 HO-functions for free! g rad U p for e m oreWednesday, October 3, 12 23
  57. 57. Static Utility Methods backwards! 24Wednesday, October 3, 12 24
  58. 58. Static Utility Methods backwards! as opposed to 24Wednesday, October 3, 12 24
  59. 59. Extension Functions 25Wednesday, October 3, 12 25
  60. 60. Extension Functions Receiver Type 25Wednesday, October 3, 12 25
  61. 61. Extension Functions Receiver Type receiver 25Wednesday, October 3, 12 25
  62. 62. Summary • Extending existing types • Without changing the classes 26Wednesday, October 3, 12 26
  63. 63. EpilogueWednesday, October 3, 12 27
  64. 64. – Dad, should I use FP? EpilogueWednesday, October 3, 12 27
  65. 65. – Dad, should I use FP? Epilogue – What is your problem?!Wednesday, October 3, 12 27
  66. 66. – Dad, should I use FP? Epilogue – What is your problem?! P.S. Kotlin is cool :) http://kotlin.jetbrains.orgWednesday, October 3, 12 27
  67. 67. Kotlin Resources • Docs: http://kotlin.jetbrains.org • Demo: http://kotlin-demo.jetbrains.com • Code: http://github.com/jetbrains/kotlin • Twitter: ➡ @project_kotlin ➡ @abreslav 28Wednesday, October 3, 12 28

×