Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Scala

         Lightning Talk
            @JSUG


Future Languages for the Java VM


      Michael Greifeneder
Overview
    Mix of functional and OO programming
●



    Static typing (performance)
●



    FP: Pattern matching, High...
Vorteile
    Scala ist kompatibel mit Java.
●


        Alle Bibliotheken können weiterverwendet
    –
        werden.
   ...
abstract class SomethingWithName(name:String) {
●

      override def toString():String = name
      def does(what:(Someth...
Output
    >scala dsl.scala
●


    Tom says Hello
●


    Swimming in pool: Tom
●


    On the ground: YellowBagger
●
Skriptsprache !?
    Folge von Statements
●


    Zugriff auf Kommandozeilenargumente
●


    println(quot;Hello quot; + a...
Closures
    Tom does ((in:SomethingWithName) =>
●

    { print(quot;Who needs closures? Maybe quot; +
    in + quot;?quot...
XML Processing
Syntax Sugar
Functional Style
Ease of Use
    Maps
●


        val map = Map(
    –
        “Austria”->”Vienna”,
        “Germany”->”Berlin”,
        “S...
Short Code
    Keine Strichpunkt notwendig.
●



    Keine geschwungenen Klammern notwendig
●


    bei einem Ausdruck
   ...
Matching Expressions
    val friend = args(0) match {
●


      case quot;saltquot; => quot;pepperquot;
      case quot;ch...
Catching Exceptions
    try {
●


      doSomething()
    } catch {
      case ex: IOException =>
                 println...
Actors! (And Action!)
    object PrintActor extends Actor{
●


      def act() = {
        var num = 0;
        react{
   ...
Upcoming SlideShare
Loading in …5
×

JSUG - Scala Lightning Talk by Michael Greifeneder

1,337 views

Published on

visit http://jsug.fsinf.at

Published in: Technology
  • Be the first to comment

  • Be the first to like this

JSUG - Scala Lightning Talk by Michael Greifeneder

  1. 1. Scala Lightning Talk @JSUG Future Languages for the Java VM Michael Greifeneder
  2. 2. Overview Mix of functional and OO programming ● Static typing (performance) ● FP: Pattern matching, High order functions, ● Parametric Polymorphism, Operator overloading Closures ● Open Source ● Functions are objects ● Perfect for domain specific languages ●
  3. 3. Vorteile Scala ist kompatibel mit Java. ● Alle Bibliotheken können weiterverwendet – werden. Scala skaliert ● Sprache kann fuer hohere Abstraktionsebenen – angepasst werden. zB Actors! Kann als Scripting Sprache verwendet ● werden Kurzer Code, aussagekraeftig ●
  4. 4. abstract class SomethingWithName(name:String) { ● override def toString():String = name def does(what:(SomethingWithName)=>unit) { what(this);}} case class Person(name:String) extends SomethingWithName(name:String) { def says(msg: String) = { print(name + quot; says quot; + msg)} def apply(name:String):Person = new Person(name)} case class Stone(name:String) extends SomethingWithName (name:String) { def apply(name:String):Bagger = new Bagger(name)} def swimming(who:SomethingWithName) = who match { case Person(name)=>print(quot;Swims in pool: quot; + name) case Stone(name)=>print(quot;On the ground: quot; + name) var Tom = Person(quot;Tomquot;) ● var YellowStone = Stone(quot;YellowStonequot;) Tom says quot;Helloquot; Tom does swimming //Tom.does(swimming) Code YellowStone does swimming;
  5. 5. Output >scala dsl.scala ● Tom says Hello ● Swimming in pool: Tom ● On the ground: YellowBagger ●
  6. 6. Skriptsprache !? Folge von Statements ● Zugriff auf Kommandozeilenargumente ● println(quot;Hello quot; + args(0) + quot;!quot;) Ausführen ● scala test.scala Shellscript ● #!/bin/sh – exec scala quot;$0quot; quot;$@quot; !# println(quot;Hello, quot; + args(0) + quot;!quot;)
  7. 7. Closures Tom does ((in:SomethingWithName) => ● { print(quot;Who needs closures? Maybe quot; + in + quot;?quot;) }) Output: ● Who needs closures? Maybe Tom? – Auch nett: ● args.foreach(arg => println(arg)) – Noch kürzer ● args.forach(println) –
  8. 8. XML Processing
  9. 9. Syntax Sugar
  10. 10. Functional Style
  11. 11. Ease of Use Maps ● val map = Map( – “Austria”->”Vienna”, “Germany”->”Berlin”, “Switzerland” -> “Bern”) map(“Austria” List ● val list = List(1,2,3) – val list2 = 1 ::: 2 ::: 3 ::: Nil
  12. 12. Short Code Keine Strichpunkt notwendig. ● Keine geschwungenen Klammern notwendig ● bei einem Ausdruck def method = x – First class functions ● args.foreach(println) – ●
  13. 13. Matching Expressions val friend = args(0) match { ● case quot;saltquot; => quot;pepperquot; case quot;chipsquot; => quot;salsaquot; case quot;eggsquot; => quot;baconquot; case _ => quot;huh?quot; } Keine Breaks notwendig ● Match kann auch Ergebnis liefern ●
  14. 14. Catching Exceptions try { ● doSomething() } catch { case ex: IOException => println(quot;Oops!quot;) case ex: NullPointerException => println(quot;Oops!!quot;) }
  15. 15. Actors! (And Action!) object PrintActor extends Actor{ ● def act() = { var num = 0; react{ case msg:String => println(num + msg) case c:Int => num+=c } } } Tester.start(); Tester ! 2 Tester ! “First Message”;

×