SlideShare a Scribd company logo
1 of 37
Download to read offline
PLAY FRAMEWORK
 Introduction & highlights of v2.1
WHO AM I?
      Andrew Skiba

I work in Tikal as the leader of
          Java group.

With over 50 Java experts, we
 meet, share, contribute, and
code together on a monthly
            basis.
YES! WE START A NEW PROJECT!
NEW PROJECT DILEMMA
WITH RISK OF ENDING UP WITH POLYGLOT PROJECT WITH
  MIX OF LANGUAGES AND TECHNOLOGIES - OR EVEN
   REWRITING PARTS OF YOUR APPLICATION LATER...
WHAT HAPPENED, TWITTER?


•   Bill Venners: I’m curious, and the Ruby folks will want it spelled
    out: Can you elaborate on what you felt the Ruby language lacked in
    the area of reliable, high performance code?

•   Steve Jenson: One of the things that I’ve found throughout my
    career is the need to have long-lived processes. And Ruby, like many
    scripting languages, has trouble being an environment for long lived
    processes. But the JVM is very good at that, because it’s been
    optimized for that over the last ten years.
JAVA IS A SAFE CHOICE
Except the risk of dying while waiting for builds & redeployments, or
                  maintaining XML configurations...
CAN YOU HAVE YOUR CAKE AND
        EAT IT, TOO?
PLAY FRAMEWORK
   Combine them all!
STRONG & FAST
Fast turnaround - just save and refresh browser
Text




     REACTIVE
Event driven non blocking IO
SCALABLE
Stateless, non blocking, web-friendly architecture
COMPLETE
Easy things are easy, complicated things are possible
DEMO OF А NEW PROJECT
IT LOOKS LIKE A MAGIC!
SO JAVA OR SCALA?
FUNCTIONAL/OO BLEND
val qsort: List[Int] => List[Int] = {
    case Nil => Nil
    case pivot :: tail =>
      val (smaller, rest) = tail.partition(_ < pivot)
      qsort(smaller) ::: pivot :: qsort(rest)
  }




             EXPRESSIVENESS
JAVA COMPATIBILITY
UNPRECEDENTED TYPE SAFETY
DSLS
COMMUNITY
'NOUGH SAID!


•   Charles Nutter, creator of JRuby: "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."

•   James Strachan, creator of Groovy: "I can honestly say if
    someone had shown me the Programming in Scala book by by
    Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd
    probably have never created Groovy."
def index = Action {
    import play.api.libs.json._

      val json = Json.obj(
        "status" -> "OK",
        "message" -> "Hello",
        "framework" -> Json.obj(
          "name" -> "Play"))

      val jsonTransformer = (
        __  'framework).json.update(
          __.read[JsObject].map { o => o ++ Json.obj("version" -> "2.1.0") })

      Ok(
        json.transform(jsonTransformer).get
      )
  }




      DEMO OF SCALA POWER
                    New JSON API with REPL
ORDER OF THINGS
app                 → Application sources
 └ assets            → Compiled asset sources
   └ stylesheets       → Typically LESS CSS sources
   └ javascripts      → Typically CoffeeScript sources
 └ controllers       → Application controllers
 └ models            → Application business layer
 └ views             → Templates
conf                → Configurationurations files and other non-compiled
resources
 └ application.conf → Main configuration file
 └ routes            → Routes definition
public              → Public assets
 └ stylesheets        → CSS files
 └ javascripts       → Javascript files
 └ images            → Image files
project             → sbt configuration files
 └ build.properties    → Marker for sbt project
 └ Build.scala       → Application build script
 └ plugins.sbt        → sbt plugins



ANATOMY OF A PLAY APPLICATION
# The home page
GET     /                                   controllers.Projects.index

# Authentication
GET     /login                              controllers.Application.login
POST    /login                              controllers.Application.authenticate
GET     /logout                             controllers.Application.logout

# ...

# Tasks
GET       /projects/:project/tasks          controllers.Tasks.index(project: Long)
POST      /projects/:project/tasks          controllers.Tasks.add(project: Long, folder: String)
PUT       /tasks/:task                      controllers.Tasks.update(task: Long)
DELETE    /tasks/:task                      controllers.Tasks.delete(task: Long)

# ...

# Javascript routing
GET     /assets/javascripts/routes          controllers.Application.javascriptRoutes

# Map static resources from the /public folder to the /assets path
GET     /assets/*file                       controllers.Assets.at(path="/public", file)




              POWERFUL URL ROUTING
POWERFUL TEMPLATE ENGINE
UNIFIED ERROR REPORTING
TASTING MENU
@org.springframework.stereotype.Service
public class HelloService {

    public String hello() {
        return "Hello world!";
    }
}
//////////////////
@org.springframework.stereotype.Controller
public class Application extends Controller {

    @Autowired
    private HelloService helloService;

    public Result index() {
        return ok(index.render(helloService.hello()));
    }
}




     SPRING WITH PLAY
DEMO OF REQUIREJS
TESTING
including a browser simulator!
in main project

# The home page
GET /               controllers.Application.index
# Include a sub-project
-> /my-subproject       my.subproject.Routes

in conf/my.subproject.routes

GET /               my.subproject.controllers.Application.index

now just surf to /my-subproject and get called
my.subproject.controllers.Application.index




        DEMO OF SUBROUTES
val query = BSONDocument("firstName" -> BSONString("Jack"))

// get a Cursor[DefaultBSONIterator]
val cursor = collection.find(query)
// let's enumerate this cursor and print a readable
// representation of each document in the response
cursor.enumerate.apply(Iteratee.foreach { doc =>
   println("found document: " + BSONDocument.pretty(doc))
})

// or, the same with getting a list
val cursor2 = collection.find(query)
val futurelist = cursor2.toList
futurelist.onSuccess {
  case list =>
    val names = list.map(_.getAs[BSONString]("lastName").get.value)
    println("got names: " + names)
}




DEMO OF REACTIVE MONGO
LINKS

•   http://www.playframework.com/ (Doh!)

•   http://typesafe.com/stack

•   http://blog.typesafe.com/scala-akka-and-play-framework-at-devoxx-2012

•   http://typesafe.com/public/case-studies/LinkedInCase_v8.pdf

•   http://docs.cloudfoundry.com/frameworks/play/java-mongodb.html

•   https://github.com/wsargent/play-2.0-spring-module

•   http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/

More Related Content

What's hot

Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in productionChristian Papauschek
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
Introduction in the play framework
Introduction in the play frameworkIntroduction in the play framework
Introduction in the play frameworkAlexander Reelsen
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Ngoc Dao
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework applicationVulcanMinds
 
Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...All Things Open
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeansRyan Cuprak
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOsNgoc Dao
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleansBill Tulloch
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Ngoc Dao
 
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)Timothy Appnel
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules uploadRyan Cuprak
 
Play Framework 2.5
Play Framework 2.5Play Framework 2.5
Play Framework 2.5m-kurz
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!David Lapsley
 
Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Matt Raible
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeSarah Z
 
Introduction to ansible galaxy
Introduction to ansible galaxyIntroduction to ansible galaxy
Introduction to ansible galaxyIvan Serdyuk
 

What's hot (20)

Using Play Framework 2 in production
Using Play Framework 2 in productionUsing Play Framework 2 in production
Using Play Framework 2 in production
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
Introduction in the play framework
Introduction in the play frameworkIntroduction in the play framework
Introduction in the play framework
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework application
 
Celery introduction
Celery introductionCelery introduction
Celery introduction
 
Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...Leveraging Open Source for Database Development: Database Version Control wit...
Leveraging Open Source for Database Development: Database Version Control wit...
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Node.js Development with Apache NetBeans
Node.js Development with Apache NetBeansNode.js Development with Apache NetBeans
Node.js Development with Apache NetBeans
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOs
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013
 
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)Ansible v2 and Beyond (Ansible Hawai'i Meetup)
Ansible v2 and Beyond (Ansible Hawai'i Meetup)
 
Preparing for java 9 modules upload
Preparing for java 9 modules uploadPreparing for java 9 modules upload
Preparing for java 9 modules upload
 
Play Framework 2.5
Play Framework 2.5Play Framework 2.5
Play Framework 2.5
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
 
Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015Developing, Testing and Scaling with Apache Camel - UberConf 2015
Developing, Testing and Scaling with Apache Camel - UberConf 2015
 
Ansible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less CoffeeAnsible: How to Get More Sleep and Require Less Coffee
Ansible: How to Get More Sleep and Require Less Coffee
 
Introduction to ansible galaxy
Introduction to ansible galaxyIntroduction to ansible galaxy
Introduction to ansible galaxy
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 

Viewers also liked

Clojure - LISP on the JVM
Clojure - LISP on the JVM Clojure - LISP on the JVM
Clojure - LISP on the JVM Tikal Knowledge
 
Play framework: lessons learned
Play framework: lessons learnedPlay framework: lessons learned
Play framework: lessons learnedPeter Hilton
 
Scalable Applications with Scala
Scalable Applications with ScalaScalable Applications with Scala
Scalable Applications with ScalaNimrod Argov
 
TCE introduction (scalability with Scala and Akka)
TCE introduction (scalability with Scala and Akka)TCE introduction (scalability with Scala and Akka)
TCE introduction (scalability with Scala and Akka)Andrew Skiba
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter HiltonJAX London
 
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...Magneta AI
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack ImplementationMert Çalışkan
 

Viewers also liked (7)

Clojure - LISP on the JVM
Clojure - LISP on the JVM Clojure - LISP on the JVM
Clojure - LISP on the JVM
 
Play framework: lessons learned
Play framework: lessons learnedPlay framework: lessons learned
Play framework: lessons learned
 
Scalable Applications with Scala
Scalable Applications with ScalaScalable Applications with Scala
Scalable Applications with Scala
 
TCE introduction (scalability with Scala and Akka)
TCE introduction (scalability with Scala and Akka)TCE introduction (scalability with Scala and Akka)
TCE introduction (scalability with Scala and Akka)
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter Hilton
 
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
Scala, Play Framework и SBT для быстрого прототипирования и разработки веб-пр...
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 

Similar to Play framework

JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developergicappa
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Pavel Kaminsky
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of usStefan Adolf
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012alexismidon
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>Arun Gupta
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsMykyta Protsenko
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstackRoberto Polli
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Enginecatherinewall
 

Similar to Play framework (20)

JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments Java 6 [Mustang] - Features and Enchantments
Java 6 [Mustang] - Features and Enchantments
 
Bye flex. Hey js.
Bye flex. Hey js.Bye flex. Hey js.
Bye flex. Hey js.
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us
 
Jet presentation
Jet presentationJet presentation
Jet presentation
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
Just one-shade-of-openstack
Just one-shade-of-openstackJust one-shade-of-openstack
Just one-shade-of-openstack
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Cannibalising The Google App Engine
Cannibalising The  Google  App  EngineCannibalising The  Google  App  Engine
Cannibalising The Google App Engine
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
React native
React nativeReact native
React native
 

Play framework

  • 1. PLAY FRAMEWORK Introduction & highlights of v2.1
  • 2. WHO AM I? Andrew Skiba I work in Tikal as the leader of Java group. With over 50 Java experts, we meet, share, contribute, and code together on a monthly basis.
  • 3. YES! WE START A NEW PROJECT!
  • 5. WITH RISK OF ENDING UP WITH POLYGLOT PROJECT WITH MIX OF LANGUAGES AND TECHNOLOGIES - OR EVEN REWRITING PARTS OF YOUR APPLICATION LATER...
  • 6. WHAT HAPPENED, TWITTER? • Bill Venners: I’m curious, and the Ruby folks will want it spelled out: Can you elaborate on what you felt the Ruby language lacked in the area of reliable, high performance code? • Steve Jenson: One of the things that I’ve found throughout my career is the need to have long-lived processes. And Ruby, like many scripting languages, has trouble being an environment for long lived processes. But the JVM is very good at that, because it’s been optimized for that over the last ten years.
  • 7. JAVA IS A SAFE CHOICE Except the risk of dying while waiting for builds & redeployments, or maintaining XML configurations...
  • 8. CAN YOU HAVE YOUR CAKE AND EAT IT, TOO?
  • 9. PLAY FRAMEWORK Combine them all!
  • 10. STRONG & FAST Fast turnaround - just save and refresh browser
  • 11. Text REACTIVE Event driven non blocking IO
  • 12. SCALABLE Stateless, non blocking, web-friendly architecture
  • 13. COMPLETE Easy things are easy, complicated things are possible
  • 14. DEMO OF А NEW PROJECT
  • 15. IT LOOKS LIKE A MAGIC!
  • 16. SO JAVA OR SCALA?
  • 18. val qsort: List[Int] => List[Int] = { case Nil => Nil case pivot :: tail => val (smaller, rest) = tail.partition(_ < pivot) qsort(smaller) ::: pivot :: qsort(rest) } EXPRESSIVENESS
  • 21. DSLS
  • 23. 'NOUGH SAID! • Charles Nutter, creator of JRuby: "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." • James Strachan, creator of Groovy: "I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy."
  • 24. def index = Action { import play.api.libs.json._ val json = Json.obj( "status" -> "OK", "message" -> "Hello", "framework" -> Json.obj( "name" -> "Play")) val jsonTransformer = ( __ 'framework).json.update( __.read[JsObject].map { o => o ++ Json.obj("version" -> "2.1.0") }) Ok( json.transform(jsonTransformer).get ) } DEMO OF SCALA POWER New JSON API with REPL
  • 26. app → Application sources └ assets → Compiled asset sources └ stylesheets → Typically LESS CSS sources └ javascripts → Typically CoffeeScript sources └ controllers → Application controllers └ models → Application business layer └ views → Templates conf → Configurationurations files and other non-compiled resources └ application.conf → Main configuration file └ routes → Routes definition public → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image files project → sbt configuration files └ build.properties → Marker for sbt project └ Build.scala → Application build script └ plugins.sbt → sbt plugins ANATOMY OF A PLAY APPLICATION
  • 27. # The home page GET / controllers.Projects.index # Authentication GET /login controllers.Application.login POST /login controllers.Application.authenticate GET /logout controllers.Application.logout # ... # Tasks GET /projects/:project/tasks controllers.Tasks.index(project: Long) POST /projects/:project/tasks controllers.Tasks.add(project: Long, folder: String) PUT /tasks/:task controllers.Tasks.update(task: Long) DELETE /tasks/:task controllers.Tasks.delete(task: Long) # ... # Javascript routing GET /assets/javascripts/routes controllers.Application.javascriptRoutes # Map static resources from the /public folder to the /assets path GET /assets/*file controllers.Assets.at(path="/public", file) POWERFUL URL ROUTING
  • 31. @org.springframework.stereotype.Service public class HelloService { public String hello() { return "Hello world!"; } } ////////////////// @org.springframework.stereotype.Controller public class Application extends Controller { @Autowired private HelloService helloService; public Result index() { return ok(index.render(helloService.hello())); } } SPRING WITH PLAY
  • 34. in main project # The home page GET / controllers.Application.index # Include a sub-project -> /my-subproject my.subproject.Routes in conf/my.subproject.routes GET / my.subproject.controllers.Application.index now just surf to /my-subproject and get called my.subproject.controllers.Application.index DEMO OF SUBROUTES
  • 35. val query = BSONDocument("firstName" -> BSONString("Jack")) // get a Cursor[DefaultBSONIterator] val cursor = collection.find(query) // let's enumerate this cursor and print a readable // representation of each document in the response cursor.enumerate.apply(Iteratee.foreach { doc => println("found document: " + BSONDocument.pretty(doc)) }) // or, the same with getting a list val cursor2 = collection.find(query) val futurelist = cursor2.toList futurelist.onSuccess { case list => val names = list.map(_.getAs[BSONString]("lastName").get.value) println("got names: " + names) } DEMO OF REACTIVE MONGO
  • 36.
  • 37. LINKS • http://www.playframework.com/ (Doh!) • http://typesafe.com/stack • http://blog.typesafe.com/scala-akka-and-play-framework-at-devoxx-2012 • http://typesafe.com/public/case-studies/LinkedInCase_v8.pdf • http://docs.cloudfoundry.com/frameworks/play/java-mongodb.html • https://github.com/wsargent/play-2.0-spring-module • http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/