Play!2 & Scala

What's the first?
¿Why the second


@noootsab

Noootsab

  • Noah's father, Sandrine's husband
  • Studied some Maths and Informatics at ULg
  • Did some work in the Geospatial fields (provisionning)
  • Also a bit in medical and web
  • Co-founded @NextLab_be (still borning)
  • Co-founded @wajug (come in!)
  • OKFN member & Hackathon eGov Wallonia believer
  • Devoxx 4 Kids trainer
  • Scala enthusiast and trainer in '14
  • Author of Learning Play! Framework 2 (Packt Publishing)
  • Big Data technologies lover

WHat is play!2

Abstract
Killer Features
Overview

Abstract

PLAY!2 IS A WEB FRAMEWORK

Written in Scala, includes Java APIs
routes : type-safe map of URL to actions (controllers)
templates : type-safe functions of type Html (f.i.)
JVM : recompilation on "app-refresh"
Assets : CoffeeScript/LESS (recompiled as well)
Errors are discovered at compile time...
... and reported in the browser!
Test: Unit (Specs), Integration (routing, db, ...), UI (~Selenium)

Killer features

  • Scala ^-^
  • Non-Blocking and Async (Netty, Akka, ...)
  • HTTP is the basis, REST is the philosophy (brings WebSocket, SSE, Comet out-of-the-box)
  • Json as first class citizen (code generation at compile time brings type safety in SeDese)
  • Open Source but supported by TypeSafe Inc.
  • JVM compliant: the Java's ecosystem is wide
  • Scala's ecosystem is evolving really fast
  • Activator reduces the needs to the browser only

Overview

Activator ui

Let's review the SSE chat template...

Scala

Let's ride the vibe...

ParadigmS

Object OrientedFunctional

Go where you feel the better

Type Types

trait (mixin)
 trait DB
class (with `new`)
 class Connection
case class (immutable and pattern matching)
 case class User
(case) object (static)
 object JDBC

modifiers

var
 class Connection {   var lastAccess = 0L // Type inferred as Long
val
 class Connection(val url:String) {   var lastAccess = 0L
lazy val
 class Connection(val url:String) {   var lastAccess = 0L   private[this] lazy val connJDBC.connectTo(url)
def
 object JDBC {   def connectTo(url:String):JDBCConnection = ...

Implicits

val
 implicit val session:DBSession case class User(first:String) {   def update(force:Boolean=false)(implicit s:DBSession) = ... }
def
 object JsonFeed {
def add(j:Json):JsonFeed = ... } object Main { implicit def userToJson(u:User):Json = ...
implicit def newsToJson(n:News):Json = ... JsonFeed.add(User("me")).add(News("Belighted hosts Scala")) }

Implicits (cont'ed)

class
 implicit class UserJson(u:User) {   def out:Out[Json] = ... } implicit class UserMessagePack(u:User) {   def out:Out[MessagePack] = ... } object JsonWorld {
import UserJson
val out = User("me").out }
object MessagePackWorld { import UserMessagePack
val out = User("me").out }

Rocking Type

Type Class
 trait JsonSer[U] {   def convert(u:U):Json } case class User(first:String) case class News(message:String) object Implicits {   implicit object UserJsonSer extends JsonSer[User] { //impl }   implicit object NewsJsonSer extends JsonSer[News] { //impl } } object JsonFeed {   def add[M : JsonSer](m:M) = implicitly[JsonSer[M]].convert(m) } object Main {   import Implicits._   JsonFeed.add(User("...")).add(News("...")) } 

Really rocks

 trait Monoid[M] {   def `0`:M   def +(m1:M, m2:M) } object Implicits {   implicit object IntMonoid extends Monoid[Int] {     val `0` = 0     def +(i1,i2) = i1 + i2   }   implicit object ListMonoid[Int] extends Monoid[List[Int]] {
val `0` = 0
def +(l1,l2) = l1 ::: l2
} } object Main { def sum[M:Monoid](list:List[M]):M = { val m = implicitly[Monoid[M]] list.foldLeft(m.`0`) { (curSum, i) => m.+(curSum, i) } }

High order Type

Helpful
 sealed trait Option[A] case class Some[A](a:A) extends Option[A] case object None extends Option[Nothing]
Powerful
 trait Future[A] {   def map[B](f:A=>B)   def flatMap[B](f:A=>Future[B]) }
Combine
for {   a <- Some(1)   b <- None } yield a + b





 for {   users <- getUsers("s")   friends <- Future.sequence(               users.flatMap(friendsOf)              ) } yield friends

MAD ZONE

Macro

QuasiQuotes

Category Theory

CPS

Workflow

LIve coding?

here we go... 
...tell me what you like
I'll try to make my best

Thanks

Discussions can go ahead on :
  • twitter (@noootsab)
  • g+ (andy.petrella)
  • github (andypetrella)


Let's grab a beer!



Come at the Hackathon eGov Wallonia

Made with Slides.com