• Save
Scala and Lift presentation
Upcoming SlideShare
Loading in...5
×
 

Scala and Lift presentation

on

  • 2,651 views

 

Statistics

Views

Total Views
2,651
Views on SlideShare
2,611
Embed Views
40

Actions

Likes
5
Downloads
0
Comments
0

2 Embeds 40

https://www.linkedin.com 33
http://www.linkedin.com 7

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Scala and Lift presentation Scala and Lift presentation Presentation Transcript

    • Liftweb
      Łukasz Kuczera
    • Scala the next Java ?
      Łukasz Kuczera
    • Scala
      Statically typed with types inferention
      Object-functional
      Compiles to Java bytecode
      And CLI .Net
    • Historia
      Pizza
      GJ
      EPFL
    • Pizza
    • Scala
      Type Inference
      Uniform Access Principle
      Closures
      Higher Order Functions
      Pattern Matching
      Actors
      Generics
      Native XML support
      Abstract control structures
      Implicit conversions and parameters
      Advanced for expressions
      Annotations
      Combinator parsing
      Traits
      Duck typing
      Null „safety”
    • „If I where to choose language other than
      Java it would be
      Scala”
    • „I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created
      Groovy”
    • „Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable”
    • Scala - Basics
      class Test {
      // variable definition
      var n = 5
      // value definition
      val i = 10
      // function definition
      def printit(x: Any) = println(x)
      def sum(i: Int, n: Int) = i+n
      }
      object Test extends Test {
      def main(args: Array[String]): Unit = {
      printit(sum(i,n))
      }
      }
    • Class Parameters - Java
      publicclass Person {
      private String name;
      privateintage;
      publicPerson(String name, int age) {
      this.name = name;
      this.age = age;
      }
      public String getName() {
      returnname;
      }
      publicvoid setName(String name) {
      this.name = name;
      }
      publicint getAge() {
      returnage;
      }
      publicvoid setAge(int age) {
      this.age = age;
      }
      }
    • Class Parameters - Scala
      classPerson(var name: String, var age: Int)
    • Working with arrays
      Java
      publicclass Partition {
      Person[] all;
      Person[] adults;
      Person[] minors;
      {
      ArrayList<Person> minorsList = new ArrayList<Person>();
      ArrayList<Person> adultsList = new ArrayList<Person>();
      for(int i=0; i<all.length; i++ ) {
      (all[i].age<18 ? adultsList: minorsList).add(all[i]);
      }
      minors = (Person[]) minorsList.toArray();
      adults = (Person[]) adultsList.toArray();
      }
      }
    • Working with arrays
      Scala
      val all: Array[Person]
      val (minors, adults) = all.partition(_.age<18)
    • Null’s – Java
      Map<String, String> capitals =
      newHashMap<String, String>();
      capitals.put("Poland", "Warsaw");
      System.out.println(capitals.get("Polska").trim());
      Exception in thread "main" java.lang.NullPointerException
    • Null’s - Scala
      val capitals = Map("Poland" -> "Warsaw");
      val capitalOption: Option[String] = capitals.get("Polska")
      capitalOption match {
      case Some(value) => println(value)
      case None => println("Not found")
      case _ =>
      }
      if(capitalOption.isDefined) println(capitalOption.get)
      println(capitalOption getOrElse "Not found")
    • XML
      val xml = <a href="http://example.com">
      <customTagb="foo">
      <deepTagb="bar" />
      Custom content
      </customTag>
      </a>
      println(xml "customTag")
      println(xml "deepTag")
      println(xml "@b")
      println(xml "customTag" "deepTag" "@b")
      Outputs:
      <customTag b="foo"><deepTag b="bar"></deepTag>Custom content</customTag>
      <deepTag b="bar"></deepTag>
      foobar
      bar
    • XML
      val xml =<divclass="rsswidget">
      <ul>
      <liclass="rsswidgettitle"><ahref="http://www.quotationspage.com/qotd.html">Quotes of the Day</a></li>
      <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/C._P._Snow">C. P. Snow</a></li>
      <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/unknown">unknown</a></li>
      <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/Frederick">Frederick</a></li>
      </ul> ...
      </div>
      (xml "@href").slice(1,4).foreach(url =>
      println("URL:"+url)
      val con = new URL(url.toString).openConnection
      val reader = newBufferedReader(newInputStreamReader(con.getInputStream, "ISO-8859-1"))
      var line = "";
      while(line != null) {
      line = reader.readLine
      if(line != null) println(line)
      }
      con.getInputStream.close
      )
    • Actors
      Easier concurrency
      Message passing instead of locks
      Asynchronus
      Implemented using Java threads
      ScalaActors, Akka, Lift - CometActor
    • Actors
      class ActorUser {
      def send(msg: Any) = ScalaActor ! msg
      }
      object ScalaActor extends Actor {
      /* The $actor's mailbox. */
      // private[actors] val mailbox = new MQueue[Msg]("Reactor")
      def act() {
      receive {
      case"ping!" => println("pinged!");
      case ("ping!", actor: Actor) => actor ! "pong!"
      case msg => println("unhandled message type:"+msg)
      }
      }
      }
    • Guice
      Minimize mutability
      Avoid static state
      @Nullable
      JSR 308 - @NonNull
    • Lift
      Chat Application Using Comet
    • Build Tools
      SBT
      Maven
      Gradle
      JRebel
    • IDE
      IntelliJ IDEA
      Netbeans
      Eclipse
    • HTTP GET
    • Ajax
    • Comet
    • Links
      http://days2010.scala-lang.org/node/136 - lots of Scala videos
      http://twit.tv/floss125 - Lifts Creator interview
      http://www.youtube.com/watch?v=01rXrI6xelE – Scala creator speak at Google tech talks
    • Thank You
      Q&A