Your SlideShare is downloading. ×
0
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Scala and Lift presentation
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Scala and Lift presentation

2,344

Published on

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

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

×