A Tour Of Scala

  • Upload
    fanf42

  • View
    6.804

  • Download
    0

Embed Size (px)

Citation preview

  1. 1. A tour of Scala Francois Armand http://fanf42.blogspot.com June 2009
  2. 2. Exploring Scala facets
    • Genesis
    • 3. Scala is...
      • Mainstream
      • 4. A scripting language
      • 5. Object Oriented
      • 6. Functional
      • 7. Scalable
  3. 8. Background - Martin Odersky history
    • Pizza 1996
      • Abetter(morefunctional ) Java
        • Generics , pattern matching, higher order function
        • 9. On the JVM
      • Sun interested
    • Generic Java (GJ) 1998/1999
      • Generics come in Java 5 (2005) with addition (wildcards...)
      • 10. GJ compiler became the default Javac for Java 1.3
    • Funnel 2000
      • Again, on the JVM - Bootstrapping is too expensive
      • 11. Pure academic experiment- too academic
    Genesis
  4. 12. Scala genesis
    • Scala since 2002
      • Martin O. join EPFL cole PolytechniquedeLausane
      • 13. Major rewrite in 2006
      • 14. Current version : 2.7.5 2.8 before end of 2009 (hopefully)
    • Initial goals
      • A better Java
      • 15. Object Oriented / Functional Programing real merge
    Genesis
  5. 16. A mainstream language
    • General purpose
    • 17. On the JVM
    • 18. Statically typed
  6. 19. General purpose
    • Web framework
    • 20. Business layer
    • 21. Side libraries
      • Test
      • 22. DSL
    • Graphical User Interface
    Scala is mainstream
  7. 23. Scala runs on the JVM
    • Compile to bytecode
    • 24. Fully compatible with Java
      • Scala code can call Java methods, select Java field, extends Java classes, implements Java interfaces
      • 25. Without any glue code / specific syntax
      • 26. And the same (almost) holds for the other way
    • => all existing Java frameworks are available
    • 27. Performances: on part with Java
    Scala is mainstream
  8. 28. Statically typed
    • One of the rare statically typed language on the JVM
    • 29. Type annotation AFTER names
    • 30. With generics and type boundaries
    • 31. With type inference
    Scala is mainstream
  9. 32. Tooling
    • Plugins for the 3 main Java IDEs
      • Netbean and Idea: quite good
      • 33. Eclipse
        • Better and better
        • 34. One people full time on it
    • JavaRebel (live class reloading)
      • Scala plugin
      • 35. Free licences
    Scala is mainstream
  10. 36. Scripting language
    • What do you want in a scripting language ?
      • Quick write / test loop
      • 37. Terse / expressive
      • 38. Duck typing
      • 39. Add methods to existing class
      • 40. Easyly usable, high level data types / control structures
  11. 41. Write and test - quickly Scala is a scripting language
    • Read / Eval / Print Loop (REPL)
      • Console interpreter
      • 42. Code completion with Scala 2.8
    • Demo: basic Scala constructs
      • Value / variable
      • 43. Function definition
      • 44. condition
  12. 45. Java without noise
    • Type inference
    • 46. Optional syntax
      • return
      • 47. .
      • 48. ;
      • 49. { } for one-line method
      • 50. ( ) when 0 or one argument
      • 51. Apply method
    • Multi-line strings
      • No need to escape special chars
    Scala is a scripting language Scala is a scripting language
  13. 52. Expressive
    • Factories
      • Defined for all collections in standard library
    • Tuples
    • 53. For comprehension
    Scala is a scripting language
  14. 54. Add methods to existing classes
    • Implicit conversions
      • Implicitly call wrappers factories to convert between types
      • 55. Checked at compile time
    • Ex: ScalaCheck
      • Implicitly call a wrapper to add should method on object Map
    Scala is a scripting language
  15. 56. Duck typing
    • If it looks like a duck and quacks like a duck, then it probably is a duck
    • 57. Structural types
      • Checked at compile time
    Scala is a scripting language
  16. 58. Real scripts, from command line
    • File helloWorld.scala
    • 59. Executed in a console: ~$ ./helloWorld.scala
    Scala is a scripting language
  17. 60. Scala is Object Oriented
    • Full OO
    • 61. With Classes and Objects
    • 62. Traits
  18. 63. Full OO
    • No primitive types
      • Everything is an object
      • 64. Even functions are objects !
    • No operators
      • Operator are simple methods
    • No static
    Scala is a object oriented
  19. 65. Classes and Objects
    • class
      • Usual Java-style classes
      • 66. A default constructor
        • In class declaration
        • 67. Other constructor MUST derive from that one
    • object
      • Scala way for static
      • 68. Singleton object
    Scala is a object oriented
  20. 69. Compared to Java Scala is a object oriented
  21. 70. Traits - 1
    • Interfaces with implementation
    • 71. Add aspects
    Scala is a object oriented
  22. 72. Traits - 2
    • Stackable
    Scala is a object oriented
  23. 73. Scala is functional
    • Values for everything
    • 74. Higher order functions
    • 75. Immutability & consistency
    • 76. Pattern matching
    • 77. Functional data structures
    • 78. Currying
    • 79. Lazy constructs
    • 80. And a lot of other things !
  24. 81. Values for everyone
    • Each block is valued
      • Easy to add logic incrementally
      • 82. Block in function parameters
    Scala is functional
  25. 83. Higher order function & Closures
    • Function = first class objects
    • 84. Closure = parameters and properties
    Scala is functional
  26. 85. Immutability and no Null by default
    • Val & Value objects
      • Immutability is easy to achieve
    • Option type
      • Null should be avoided
    • Immutable collections
      • Available in standard library
    Scala is functional
  27. 86. Add new control structures
    • Look natives
      • Valued blocks
      • 87. + Higher order functions & closures
      • 88. + optional syntax
      • 89. = easy extension of the language by libraries
    • Ex : no break keyword in Scala: add it yourself !
    Scala is functional
  28. 90. Functional Data Structures
    • The almighty List
      • Methods available for all Collections
    Scala is a functional
  29. 91. Pattern matching - 1
      • Switch under vitamins
      • 92. Deconstruct object graph Why ?
        • Work on semi-structured datas : XML, Rexeps, etc
        • 93. Two many methods needed to have them in a top-level object
        • 94. When methods (or top-level object) not under your control
    Scala is a functional
  30. 95. Pattern matching - 2
    • Case classes
      • Define your own patterns
      • 96. Automatically add equals/hashcode and Factories for you
      • 97. sealed => compiler checks that all choices are tested
    Scala is a functional
  31. 98. Currying
    • Function with a list of arguments
    • 99. == function with multiple argument lists
    • 100. Define new specialized functions easily
      • Division of labour
    Scala is a functional
  32. 101. Lazy constructs - 1
    • Lazy = evaluated only when needed
    Scala is a functional
  33. 102. Lazy constructs - 2
    • Create infinite Collections
    Scala is a functional
  34. 103. A lots of other things
    • Self types
    • 104. Abstract type
    • 105. Existential types
    • 106. Type variance
    • 107. Monads
    • 108. Combinatory parsers
    • 109. And a lot more
  35. 110. So, Why Scala ?
    • Scalable language
      • Scala is deep, not broad
      • 111. Scale in large
        • Object / class hierarchies, traits compositions
      • Scale in small
        • Functional aspects: composable small methods
        • 112. => Unix pipes
      • Easy to add
        • New Data types
        • 113. New Control Structures
        • 114. Look native
      • Great for DSL
  36. 115. DSL: Actors Scalable language
  37. 116. DSL: XML Scala is a functional
  38. 117. Successful (?)
    • Get more and more attention
      • 6 talks at JavaOne 2009 + ScalaLiftOff one full day of Scala
      • 118. 4 books (and 2 other by the end of 2009)
      • 119. Active mailing list / irc channel
      • 120. Several external commiters on the compiler
    • Who used it ?
      • Open Source projects
        • Lift -http://liftweb.net : web framework,full stack
        • 121. Apache Camel / NetBeans / ScalaSpec / ScalaCheck...
      • Commercial
        • Twitter / Sony / Mimesis Republic / EDF trading / SAP
    Last words
  39. 122. Scala 2.8 preview end of 2009
    • Redesigned collection library
    • 123. Named and default parameters
    • 124. Package object
    • 125. Scala Swing library
    • 126. Revamped REPL
    • 127. Type specialization
    • 128. Continuation (as a plugin compiler)
    Last words
  40. 129. Questions ?
    • http://scala-lang.org
    • 130. http://www.artima.com