SlideShare ist ein Scribd-Unternehmen logo
1 von 37
Downloaden Sie, um offline zu lesen
Scala – The Next 5 Years

       Martin Odersky
It’s been quite a ride
The last 6 years

2003   Scala first used in classroom at EPFL.
2004   First public release,
       Jamie & Jon at Sygneca are probably first
       outside professional users.
2005   Scalable component abstractions paper.
2006   2.x version released, David Pollak
       gets interested.
2007   First JavaOne talk.
2008   First Scala LiftOff Unconference.
2009   JavaOne talks on Scala almost fill a full day.
Even more rewarding:

  We have a fantastic user community:
  Friendly, helpful, and intelligent.

  A big Thank You to our contributors. We could not have
  done it without you.
What is Scala, exactly?
A scripting language?

Scala is a regular contender at
JavaOne’s ScriptBowl.                 var capital = Map( "US" → "Washington",
                                                          "France" → "paris",
Syntax is lightweight                                     "Japan" → "tokyo" )
and concise, due to:
                                      capital += "Russia" → "Moskow"
 –   semicolon inference,
 –   type inference,                  for ( (country, city) ← capital )
 –   lightweight classes,                 capital += country → city.capitalize
 –   extensible API’s,
 –   closures as                      assert ( capital("Japan") == "Tokyo" )
     control abstractions.

 Average reduction in LOC wrt Java: ≥ 2
  due to concise syntax and better abstraction capabilities.
 Explorative programming with a read-eval-print-loop (REPL)
The Java of the future?
It has basically everything Java has now.
     (sometimes in different form)
It has closures.
     (proposed for Java 7, but rejected)
It has traits and pattern matching.
     (I would not be surprised to see them in Java 8, 9 or 10)
It compiles to .class files, is completely interoperable and runs about as
     fast as Java

     object App {   
       def main(args: Array[String]) { 
         if (args exists (_.toLowerCase == "‐help")) 
           printUsage()
         else 
           process(args)
       }
     }
A language for concurrent programming?

It has powerful concurrency
                                  // asynchronous message send
abstractions such as actors.
                                  actor ! message

It’s used in heavy duty
applications: kestrel message     // message receive
queue, lift web framework.        receive {
                                    case msgpat1 => action1
It makes functional programming     …    
with immutable data easy.
                                    case msgpatn => actionn
                                  }
A composition language?

•   New approach to module
    systems:                      trait Analyzer { this: Backend =>
     component = class or trait     …
                                  }
     composition via mixins
•   Components connect with       trait Backend extends Analyzer
                                                with Optimization
     – parameters,                              with Generation {
     – abstract members (both
                                    val global: Main
        types and values),          import global._
     – self types
                                    type OutputMedium <: Writable
•   gives dependency injection
    for free                      }
How can it be all these things?

Q. Is there not a danger that a language being all of these
  things becomes too complex?

A. Normally, yes. However, Scala is deep where other
   languages are broad.

  Cuts down on boilerplate.

  Concentrates on powerful abstraction methods, so that
  users can write powerful libraries.
The Essence of Scala

Key design principles of Scala:

1. Concentrate on scalability: The same constructions
   should work for small as well as large programs.

2. Unify object-oriented and functional programming.
Where do we go from here?

• Summer/fall 2009: Scala 2.8, with:
   –   new collections
   –   package objects
   –   named and default parameters
   –   @specialized for faster generics
   –   improved tool support for IDEs and REPL.


• The next 5 years:

   Concurrency // Parallelism
   (on all levels: primitives, abstractions, types, tools)
Old Scala collections
•   Pre 2.8 collections have grown gradually. They lack a uniform
    structure.
•   Examples:

       scala.Seq
       scala.RandomAccessSeq.Mutable
       scala.collection.mutable.Set

•   Operations like map need to be redefined for every collection type:

       List(1, 2, 3).map(inc) : List[Int]
       Array(1, 2, 3).map(inc): Array[Int]
       Set(1, 2, 3).map(inc)  : Set[Int]
New Scala collections

• Uniform structure:
     scala.collection.immutableList
     scala.collection.immutable.Set
     scala.collection.mutable.Vector
• Every operation is implemented only once.
• Selection of building blocks in package
  scala.collection.generic.
Collection Hierarchy
Package Objects

Problem: Everything has to live inside an object or class.
   => No top-level value definitions, type aliases, implicits.

Package objects make packages more like objects.

They also let you define your own ``Predefs’’.

      package object scala {
        type List[+T] = scala.collection.immutable.List 
        val List = scala.collection.immutable.List
        ...
      } 
Named and default arguments
 def newTable(size: Int = 100, load: Float = 0.5f) =
     new HashMap[String, String]{
         override val initialSize = size
         override val loadFactor = (load * 1000).toInt
     }
 }
 newTable(50, 0.75f)
 newTable()
 newTable(load = 0.5f)
 newTable(size = 20, load = 0.5f)


Defaults can be arbitrary expressions, not just constants.
Default evaluation is dynamic.
Copy method
Problem: Case classes are great for pattern matching,
  but how do you transform data?
Often need to update (functionally) some specific field(s)
  of a date structure defined by case classes.
Solution: Selective copy method.

  case class Tree[+T](elem: T, left: Tree[T], right: Tree[T])


  def incElem(t: Tree[Int])  =  t copy (elem = t.elem + 1)




• Problem: How to define “copy”?
Defining copy

• Problem: A class with n parameters allows 2n possible
  combinations of parameters to copy.
• Default parameters to the rescue.

  case class Tree[+T](elem: T, left: Tree[T], right: Tree[T]) {
    // generated automatically:
    def copy[U](elem: U = this.elem, 
                left: Tree[U] = this.left,
                right: Tree[U] = this.right) = 
      Branch(elem, left, right)    
  }
Using copy
scala> case class Tree[T](elem: T, left: Tree[T], right: Tree[T])
defined class Tree


scala> val t = Tree(1, null, null)
t: Tree[Int] = Tree(1,null,null)


scala> val u = t.copy(left = Tree(2, null, null))
u: Tree[Int] = Tree(1,Tree(2,null,null),null)


scala> val v = u.copy(elem = 3, right = Tree(4, null, null))
v: Tree[Int] = Tree(3,Tree(2,null,null),Tree(4,null,null))
Faster Generics

• Problem: Generics cause a performance hit because
  they require a uniform representation: everything needs
  to be boxed.
                    trait Function1[‐T, +U] { def apply(x: T): U }
• Example:
                      def app(x: Int, fn: Int => Int) = fn(x)
                      app(7, x => x * x)


  becomes:            trait Function1 { def apply(x: Object): Object }
                      class anonfun extends Function1 {
                        def apply(x: Object): Object =
                          Int.box(apply(Int.unbox(x)))
                        def apply(x: Int): Int = x * x
                      }
                      def app(x: Int, fn: Function1) = 
                        Int.unbox(fn(Int.box(x)))
                      app(7, new anonfun)
Solution: @specialized

• We should specialize functions that take primitive
  parameter types.
• If we had the whole program at our disposal, this would
  be easy: Just do it like C++ templates.
• The problem is that we don’t.
• Idea: specialize opportunistically, when types are known.
If Function1 is @specialized ...
  trait Function1[@specialized ‐T, @specialized +U] {
    def apply(x: T): U }
  def app(x: Int, fn: Int => Int) = fn(x)
  app(7, x => x * x)

... the compiler generates instead:
  trait Function1 {
    def apply(x: Object): Object
    def applyIntInt(x: Int): Int =
      Int.unbox(apply(Int.box(x)))
    // specializations for other primitive types
  }                                                     No boxing!
  class anonfun extends (Int => Int) {
    def apply(x: Object): Object =
      Int.box(applyIntInt(Int.unbox(x)))
    override def applyIntInt(x: Int): Int = x * x
  }
  def app(x: Int, fn: Function1) =
  fn.applyIntInt(x)
  app(7, anonfun)
Better tools

• REPL with command completion (courtesy Paul Phillips).

• Reworked IDE/compiler interface (Miles Sabin, Martin
  Odersky, Iulian Dragos).

   Developed originally for Eclipse, but should be reusable for
   other IDEs such as Netbeans, VisualStudio.
New control abstractions:

• Continations plugin
   – allow to unify receive and react in actors.
   – give a clean basis for encpsulating nio.
   – let you do lots of other control abstractions.
• Break (done in library)
• Trampolining tail calls (done in library)
   import scala.util.control.Breaks._
   breakable {
     for (x <- elems) {
       println(x * 2)
       if (x > 0) break
     }
   }
Slipping break back into Scala.
More features

• Extended swing library.
• Performance improvements, among others for
   – structural type dispatch,
   – actors,
   – vectors, sets and maps.
• Standardized compiler plugin architecture.
How to get 2.8

Can use trunk today (bleeding edge).

Stable preview planned for July.

Final version planned for September or October.
Beyond 2.8
New challenges

Concurrency:

   How to make concurrent activities play well together?

Parallelism:

   How to extract better performance from today’s and
   tomorrow’s parallel processors (multicores, gpus, etc).

The two do not necessarily have the same solutions!
What can be done?

(1) Better abstractions:

  Actors
  Transactions
  Join patterns
  Stream processing with single-assignment variables
  Data parallelism
(2) Better Analyses.    Distinguish between:

  pure:             no side effects
  thread-local:     no interaction
  transactional:    atomic interaction
  unrestricted access (danger!)

  Need alias tracking and effect systems.
  Problem: can we make these lightweight enough?
(3) Better support for static types.

  Need to overcome the “type wall”.

  Static typing is a key ingredient for reliable concurrent
  programs, yet programs are annoyingly hard to get right.

  Need better tools: Type browsers, type debuggers.

  Need better presentations: Users might not always want
  to see the most general type!
Why Scala?

  I believe Scala is well placed as a basis for concurrent
  and parallel programming, because

   – It runs natively on the JVM.
   – It supports functional programming.
   – It has great syntactic flexibility.


• Btw we are not the only ones to have recognized this:
   – The X10, PPL, Fortress are al using Scala in some role or other.
Learning Scala

•   To get started:
•   First steps in Scala, by Bill Venners
    published in Scalazine at
    www.artima.com

•   Scala for Java Refugees by Daniel
    Spiewack (great blog series)

•   To continue:
     3+1 books published; more in the pipeline.
How to find out more

Track it on
scala-lang.org:




Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Derek Chen-Becker
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Introduction to programming in scala
Introduction to programming in scalaIntroduction to programming in scala
Introduction to programming in scalaAmuhinda Hungai
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 

Was ist angesagt? (16)

Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
scala
scalascala
scala
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Google06
Google06Google06
Google06
 
Introduction to programming in scala
Introduction to programming in scalaIntroduction to programming in scala
Introduction to programming in scala
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 

Andere mochten auch

downey08semaphores.pdf
downey08semaphores.pdfdowney08semaphores.pdf
downey08semaphores.pdfHiroshi Ono
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfHiroshi Ono
 
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfstateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfHiroshi Ono
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfHiroshi Ono
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfHiroshi Ono
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdfHiroshi Ono
 
TwitterOct2008.pdf
TwitterOct2008.pdfTwitterOct2008.pdf
TwitterOct2008.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdfHiroshi Ono
 
SACSIS2009_TCP.pdf
SACSIS2009_TCP.pdfSACSIS2009_TCP.pdf
SACSIS2009_TCP.pdfHiroshi Ono
 
Canonical and robotos (2)
Canonical and robotos (2)Canonical and robotos (2)
Canonical and robotos (2)panchaloha
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdfHiroshi Ono
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfHiroshi Ono
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdfHiroshi Ono
 
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfstateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfHiroshi Ono
 

Andere mochten auch (18)

downey08semaphores.pdf
downey08semaphores.pdfdowney08semaphores.pdf
downey08semaphores.pdf
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdf
 
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfstateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdf
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdf
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdf
 
TwitterOct2008.pdf
TwitterOct2008.pdfTwitterOct2008.pdf
TwitterOct2008.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdf
 
SACSIS2009_TCP.pdf
SACSIS2009_TCP.pdfSACSIS2009_TCP.pdf
SACSIS2009_TCP.pdf
 
Canonical and robotos (2)
Canonical and robotos (2)Canonical and robotos (2)
Canonical and robotos (2)
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdf
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdf
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdf
 
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdfstateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
stateyouredoingitwrongjavaone2009-090617031310-phpapp02.pdf
 

Ähnlich wie scalaliftoff2009.pdf

An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsMiles Sabin
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaScala Italy
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional ProgrammingAapo Kyrölä
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with ScalaNeelkanth Sachdeva
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistpmanvi
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play frameworkFelipe
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos3Pillar Global
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyTypesafe
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Languageleague
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slidesMartin Odersky
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosGenevaJUG
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmerGirish Kumar A L
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene BurmakoVasil Remeniuk
 

Ähnlich wie scalaliftoff2009.pdf (20)

An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Devoxx
DevoxxDevoxx
Devoxx
 
About Functional Programming
About Functional ProgrammingAbout Functional Programming
About Functional Programming
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
 
ScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin OderskyScalaDays 2013 Keynote Speech by Martin Odersky
ScalaDays 2013 Keynote Speech by Martin Odersky
 
Scala google
Scala google Scala google
Scala google
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slides
 
Flatmap
FlatmapFlatmap
Flatmap
 
Scala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian DragosScala at GenevaJUG by Iulian Dragos
Scala at GenevaJUG by Iulian Dragos
 
Introduction to scala for a c programmer
Introduction to scala for a c programmerIntroduction to scala for a c programmer
Introduction to scala for a c programmer
 
scala.reflect, Eugene Burmako
scala.reflect, Eugene Burmakoscala.reflect, Eugene Burmako
scala.reflect, Eugene Burmako
 

Mehr von Hiroshi Ono

Voltdb - wikipedia
Voltdb - wikipediaVoltdb - wikipedia
Voltdb - wikipediaHiroshi Ono
 
Gamecenter概説
Gamecenter概説Gamecenter概説
Gamecenter概説Hiroshi Ono
 
EventDrivenArchitecture
EventDrivenArchitectureEventDrivenArchitecture
EventDrivenArchitectureHiroshi Ono
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdfHiroshi Ono
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfHiroshi Ono
 
downey08semaphores.pdf
downey08semaphores.pdfdowney08semaphores.pdf
downey08semaphores.pdfHiroshi Ono
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdfHiroshi Ono
 
TwitterOct2008.pdf
TwitterOct2008.pdfTwitterOct2008.pdf
TwitterOct2008.pdfHiroshi Ono
 
pamphlet_honsyou.pdf
pamphlet_honsyou.pdfpamphlet_honsyou.pdf
pamphlet_honsyou.pdfHiroshi Ono
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdfHiroshi Ono
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdfHiroshi Ono
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 

Mehr von Hiroshi Ono (16)

Voltdb - wikipedia
Voltdb - wikipediaVoltdb - wikipedia
Voltdb - wikipedia
 
Gamecenter概説
Gamecenter概説Gamecenter概説
Gamecenter概説
 
EventDrivenArchitecture
EventDrivenArchitectureEventDrivenArchitecture
EventDrivenArchitecture
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdf
 
kademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdfkademlia-1227143905867010-8.pdf
kademlia-1227143905867010-8.pdf
 
downey08semaphores.pdf
downey08semaphores.pdfdowney08semaphores.pdf
downey08semaphores.pdf
 
BOF1-Scala02.pdf
BOF1-Scala02.pdfBOF1-Scala02.pdf
BOF1-Scala02.pdf
 
TwitterOct2008.pdf
TwitterOct2008.pdfTwitterOct2008.pdf
TwitterOct2008.pdf
 
pamphlet_honsyou.pdf
pamphlet_honsyou.pdfpamphlet_honsyou.pdf
pamphlet_honsyou.pdf
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
program_draft3.pdf
program_draft3.pdfprogram_draft3.pdf
program_draft3.pdf
 
nodalities_issue7.pdf
nodalities_issue7.pdfnodalities_issue7.pdf
nodalities_issue7.pdf
 
genpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdfgenpaxospublic-090703114743-phpapp01.pdf
genpaxospublic-090703114743-phpapp01.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 

scalaliftoff2009.pdf

  • 1. Scala – The Next 5 Years Martin Odersky
  • 3. The last 6 years 2003 Scala first used in classroom at EPFL. 2004 First public release, Jamie & Jon at Sygneca are probably first outside professional users. 2005 Scalable component abstractions paper. 2006 2.x version released, David Pollak gets interested. 2007 First JavaOne talk. 2008 First Scala LiftOff Unconference. 2009 JavaOne talks on Scala almost fill a full day.
  • 4.
  • 5. Even more rewarding: We have a fantastic user community: Friendly, helpful, and intelligent. A big Thank You to our contributors. We could not have done it without you.
  • 6. What is Scala, exactly?
  • 7. A scripting language? Scala is a regular contender at JavaOne’s ScriptBowl. var capital = Map( "US" → "Washington", "France" → "paris", Syntax is lightweight "Japan" → "tokyo" ) and concise, due to: capital += "Russia" → "Moskow" – semicolon inference, – type inference, for ( (country, city) ← capital ) – lightweight classes, capital += country → city.capitalize – extensible API’s, – closures as assert ( capital("Japan") == "Tokyo" ) control abstractions. Average reduction in LOC wrt Java: ≥ 2 due to concise syntax and better abstraction capabilities. Explorative programming with a read-eval-print-loop (REPL)
  • 8. The Java of the future? It has basically everything Java has now. (sometimes in different form) It has closures. (proposed for Java 7, but rejected) It has traits and pattern matching. (I would not be surprised to see them in Java 8, 9 or 10) It compiles to .class files, is completely interoperable and runs about as fast as Java object App {      def main(args: Array[String]) {      if (args exists (_.toLowerCase == "‐help"))        printUsage()     else        process(args)   } }
  • 9. A language for concurrent programming? It has powerful concurrency // asynchronous message send abstractions such as actors. actor ! message It’s used in heavy duty applications: kestrel message // message receive queue, lift web framework. receive {   case msgpat1 => action1 It makes functional programming   …     with immutable data easy.   case msgpatn => actionn }
  • 10. A composition language? • New approach to module systems: trait Analyzer { this: Backend => component = class or trait   … } composition via mixins • Components connect with trait Backend extends Analyzer               with Optimization – parameters,               with Generation { – abstract members (both   val global: Main types and values),   import global._ – self types   type OutputMedium <: Writable • gives dependency injection for free }
  • 11. How can it be all these things? Q. Is there not a danger that a language being all of these things becomes too complex? A. Normally, yes. However, Scala is deep where other languages are broad. Cuts down on boilerplate. Concentrates on powerful abstraction methods, so that users can write powerful libraries.
  • 12. The Essence of Scala Key design principles of Scala: 1. Concentrate on scalability: The same constructions should work for small as well as large programs. 2. Unify object-oriented and functional programming.
  • 13. Where do we go from here? • Summer/fall 2009: Scala 2.8, with: – new collections – package objects – named and default parameters – @specialized for faster generics – improved tool support for IDEs and REPL. • The next 5 years: Concurrency // Parallelism (on all levels: primitives, abstractions, types, tools)
  • 14. Old Scala collections • Pre 2.8 collections have grown gradually. They lack a uniform structure. • Examples: scala.Seq scala.RandomAccessSeq.Mutable scala.collection.mutable.Set • Operations like map need to be redefined for every collection type: List(1, 2, 3).map(inc) : List[Int] Array(1, 2, 3).map(inc): Array[Int] Set(1, 2, 3).map(inc)  : Set[Int]
  • 15. New Scala collections • Uniform structure: scala.collection.immutableList scala.collection.immutable.Set scala.collection.mutable.Vector • Every operation is implemented only once. • Selection of building blocks in package scala.collection.generic.
  • 17. Package Objects Problem: Everything has to live inside an object or class. => No top-level value definitions, type aliases, implicits. Package objects make packages more like objects. They also let you define your own ``Predefs’’. package object scala {   type List[+T] = scala.collection.immutable.List    val List = scala.collection.immutable.List   ... } 
  • 18. Named and default arguments def newTable(size: Int = 100, load: Float = 0.5f) = new HashMap[String, String]{ override val initialSize = size override val loadFactor = (load * 1000).toInt } } newTable(50, 0.75f) newTable() newTable(load = 0.5f) newTable(size = 20, load = 0.5f) Defaults can be arbitrary expressions, not just constants. Default evaluation is dynamic.
  • 19. Copy method Problem: Case classes are great for pattern matching, but how do you transform data? Often need to update (functionally) some specific field(s) of a date structure defined by case classes. Solution: Selective copy method. case class Tree[+T](elem: T, left: Tree[T], right: Tree[T]) def incElem(t: Tree[Int])  =  t copy (elem = t.elem + 1) • Problem: How to define “copy”?
  • 20. Defining copy • Problem: A class with n parameters allows 2n possible combinations of parameters to copy. • Default parameters to the rescue. case class Tree[+T](elem: T, left: Tree[T], right: Tree[T]) {   // generated automatically:   def copy[U](elem: U = this.elem,                left: Tree[U] = this.left,               right: Tree[U] = this.right) =      Branch(elem, left, right)     }
  • 22. Faster Generics • Problem: Generics cause a performance hit because they require a uniform representation: everything needs to be boxed. trait Function1[‐T, +U] { def apply(x: T): U } • Example: def app(x: Int, fn: Int => Int) = fn(x) app(7, x => x * x) becomes: trait Function1 { def apply(x: Object): Object } class anonfun extends Function1 {   def apply(x: Object): Object =     Int.box(apply(Int.unbox(x)))   def apply(x: Int): Int = x * x } def app(x: Int, fn: Function1) =    Int.unbox(fn(Int.box(x))) app(7, new anonfun)
  • 23. Solution: @specialized • We should specialize functions that take primitive parameter types. • If we had the whole program at our disposal, this would be easy: Just do it like C++ templates. • The problem is that we don’t. • Idea: specialize opportunistically, when types are known.
  • 24. If Function1 is @specialized ... trait Function1[@specialized ‐T, @specialized +U] {   def apply(x: T): U } def app(x: Int, fn: Int => Int) = fn(x) app(7, x => x * x) ... the compiler generates instead: trait Function1 {   def apply(x: Object): Object   def applyIntInt(x: Int): Int =     Int.unbox(apply(Int.box(x)))   // specializations for other primitive types } No boxing! class anonfun extends (Int => Int) {   def apply(x: Object): Object =     Int.box(applyIntInt(Int.unbox(x)))   override def applyIntInt(x: Int): Int = x * x } def app(x: Int, fn: Function1) = fn.applyIntInt(x) app(7, anonfun)
  • 25. Better tools • REPL with command completion (courtesy Paul Phillips). • Reworked IDE/compiler interface (Miles Sabin, Martin Odersky, Iulian Dragos). Developed originally for Eclipse, but should be reusable for other IDEs such as Netbeans, VisualStudio.
  • 26. New control abstractions: • Continations plugin – allow to unify receive and react in actors. – give a clean basis for encpsulating nio. – let you do lots of other control abstractions. • Break (done in library) • Trampolining tail calls (done in library) import scala.util.control.Breaks._ breakable { for (x <- elems) { println(x * 2) if (x > 0) break } }
  • 27. Slipping break back into Scala.
  • 28. More features • Extended swing library. • Performance improvements, among others for – structural type dispatch, – actors, – vectors, sets and maps. • Standardized compiler plugin architecture.
  • 29. How to get 2.8 Can use trunk today (bleeding edge). Stable preview planned for July. Final version planned for September or October.
  • 31. New challenges Concurrency: How to make concurrent activities play well together? Parallelism: How to extract better performance from today’s and tomorrow’s parallel processors (multicores, gpus, etc). The two do not necessarily have the same solutions!
  • 32. What can be done? (1) Better abstractions: Actors Transactions Join patterns Stream processing with single-assignment variables Data parallelism
  • 33. (2) Better Analyses. Distinguish between: pure: no side effects thread-local: no interaction transactional: atomic interaction unrestricted access (danger!) Need alias tracking and effect systems. Problem: can we make these lightweight enough?
  • 34. (3) Better support for static types. Need to overcome the “type wall”. Static typing is a key ingredient for reliable concurrent programs, yet programs are annoyingly hard to get right. Need better tools: Type browsers, type debuggers. Need better presentations: Users might not always want to see the most general type!
  • 35. Why Scala? I believe Scala is well placed as a basis for concurrent and parallel programming, because – It runs natively on the JVM. – It supports functional programming. – It has great syntactic flexibility. • Btw we are not the only ones to have recognized this: – The X10, PPL, Fortress are al using Scala in some role or other.
  • 36. Learning Scala • To get started: • First steps in Scala, by Bill Venners published in Scalazine at www.artima.com • Scala for Java Refugees by Daniel Spiewack (great blog series) • To continue: 3+1 books published; more in the pipeline.
  • 37. How to find out more Track it on scala-lang.org: Thank You