A tour of Scala Francois Armand http://fanf42.blogspot.com June 2009
Exploring Scala facets <ul><li>Genesis
Scala is... </li><ul><li>Mainstream
A scripting language
Object Oriented
Functional
Scalable </li></ul></ul>
Background - Martin Odersky history  <ul><li>Pizza – 1996 </li><ul><li>A  better  (more  functional ) Java </li><ul><li>Ge...
On the JVM </li></ul><li>Sun interested </li></ul><li>Generic Java (GJ) – 1998/1999 </li><ul><li>Generics come in Java 5 (...
GJ compiler became the default Javac for Java 1.3 </li></ul><li>Funnel – 2000 </li><ul><li>Again, on the JVM - “Bootstrapp...
Pure academic experiment  - too academic </li></ul></ul>Genesis
Scala genesis  <ul><li>Scala – since 2002 </li><ul><li>Martin O. join EPFL –  École   Polytechnique  de  Lausane
Major rewrite in 2006
Current version : 2.7.5 – 2.8 before end of 2009 (hopefully) </li></ul><li>Initial goals </li><ul><li>A better Java
Object Oriented / Functional Programing real merge </li></ul></ul>Genesis
A mainstream language <ul><li>General purpose
On the JVM
Statically typed </li></ul>
General purpose <ul><li>Web framework
Business layer
Side libraries  </li><ul><li>Test
DSL </li></ul><li>Graphical User Interface </li></ul>Scala is mainstream
Scala runs on the JVM <ul><li>Compile to bytecode
Fully compatible with Java </li><ul><li>Scala code can call Java methods, select Java field, extends Java classes, impleme...
Without any glue code / specific syntax
And the same (almost) holds for the other way </li></ul><li>=> all existing Java frameworks are available
Performances: on part with Java </li></ul>Scala is mainstream
Statically typed <ul><li>One of the rare statically typed language on the JVM
Type annotation AFTER names
With generics and type boundaries
With type inference </li></ul>Scala is mainstream
Tooling <ul><li>Plugins for the 3 main Java IDEs </li><ul><li>Netbean and Idea: quite good
Eclipse  </li><ul><li>Better and better
One people full time on it </li></ul></ul><li>JavaRebel (live class reloading) </li><ul><li>Scala plugin
Free licences </li></ul></ul>Scala is mainstream
Scripting language <ul><li>What do you want in a scripting language ? </li><ul><li>Quick write / test loop
Terse / expressive
Duck typing
Add methods to existing class
Easyly usable, high level data types / control structures </li></ul></ul>
Upcoming SlideShare
Loading in...5
×

A Tour Of Scala

6,803

Published on

A general presentation of the Scala language, a OO/functional, statically typed language that runs on the JVM

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

No Downloads
Views
Total Views
6,803
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
362
Comments
0
Likes
16
Embeds 0
No embeds

No notes for slide

A Tour Of Scala

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

    Clipping is a handy way to collect important slides you want to go back to later.

×