Liftweb<br />Łukasz Kuczera<br />
Scala the next Java ?<br />Łukasz Kuczera<br />
Scala<br />Statically typed with types inferention<br />Object-functional<br />Compiles to Java bytecode<br />And CLI .Net...
Historia<br />Pizza<br />GJ<br />EPFL<br />
Pizza<br />
Scala<br />Type Inference<br />Uniform Access Principle<br />Closures<br />Higher Order Functions<br />Pattern Matching<br...
„If I where to choose language other than<br />Java it would be <br />Scala”<br />
„I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back...
„Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable ...
Scala - Basics<br />class Test {<br />// variable definition<br />var n = 5<br />// value definition<br />val i = 10<br />...
Class Parameters - Java<br />publicclass Person {<br />	private String name;<br />	privateintage;<br />publicPerson(String...
Class Parameters - Scala<br />classPerson(var name: String, var age: Int)<br />
Working with arrays<br />Java<br />publicclass Partition {<br />Person[] all;<br />Person[] adults;<br />Person[] minors;<...
Working with arrays<br />Scala<br />val all: Array[Person]<br />val (minors, adults) = all.partition(_.age<18)<br />
Null’s – Java<br />Map<String, String> capitals = <br />newHashMap<String, String>();<br />capitals.put("Poland", "Warsaw"...
Null’s - Scala<br />  val capitals = Map("Poland" -> "Warsaw");<br />val capitalOption: Option[String] = capitals.get("Pol...
XML<br />val xml = <a href="http://example.com"><br />		    <customTagb="foo"><br />		       <deepTagb="bar" /><br />Custo...
XML<br />val xml =<divclass="rsswidget"><br /><ul><br /><liclass="rsswidgettitle"><ahref="http://www.quotationspage.com/qo...
Actors<br />Easier concurrency<br />Message passing instead of locks<br />Asynchronus<br />Implemented using Java threads<...
Actors<br />class ActorUser {<br />def send(msg: Any) = ScalaActor ! msg<br />}<br />object ScalaActor extends Actor {<br ...
Guice<br />Minimize mutability<br />Avoid static state<br />@Nullable<br />JSR 308 - @NonNull<br />
Lift<br />Chat Application Using Comet<br />
Build Tools<br />SBT <br />Maven<br />Gradle<br />JRebel<br />
IDE	<br />IntelliJ IDEA<br />Netbeans<br />Eclipse<br />
HTTP GET<br />
Ajax<br />
Comet<br />
Links<br />http://days2010.scala-lang.org/node/136 - lots of Scala videos<br />http://twit.tv/floss125 - Lifts Creator int...
Thank You<br />Q&A<br />
Upcoming SlideShare
Loading in...5
×

Scala and Lift presentation

2,348

Published on

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,348
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Transcript of "Scala and Lift presentation"

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

×