Scala and Lift presentation

  • 2,265 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,265
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Liftweb
    Łukasz Kuczera
  • 2. Scala the next Java ?
    Łukasz Kuczera
  • 3. Scala
    Statically typed with types inferention
    Object-functional
    Compiles to Java bytecode
    And CLI .Net
  • 4. Historia
    Pizza
    GJ
    EPFL
  • 5. Pizza
  • 6.
  • 7.
  • 8. 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”
  • 9. „If I where to choose language other than
    Java it would be
    Scala”
  • 10. „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”
  • 11. „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”
  • 12.
  • 13. 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))
    }
    }
  • 14. 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;
    }
    }
  • 15. Class Parameters - Scala
    classPerson(var name: String, var age: Int)
  • 16. 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();
    }
    }
  • 17. Working with arrays
    Scala
    val all: Array[Person]
    val (minors, adults) = all.partition(_.age<18)
  • 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
  • 19. 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")
  • 20. 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
  • 21. 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
    )
  • 22. Actors
    Easier concurrency
    Message passing instead of locks
    Asynchronus
    Implemented using Java threads
    ScalaActors, Akka, Lift - CometActor
  • 23. 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)
    }
    }
    }
  • 24. Guice
    Minimize mutability
    Avoid static state
    @Nullable
    JSR 308 - @NonNull
  • 25. Lift
    Chat Application Using Comet
  • 26. Build Tools
    SBT
    Maven
    Gradle
    JRebel
  • 27. IDE
    IntelliJ IDEA
    Netbeans
    Eclipse
  • 28. HTTP GET
  • 29. Ajax
  • 30. Comet
  • 31.
  • 32. 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
  • 33. Thank You
    Q&A