Cw13 playing with scala by tamer abdelradi

8
Play-ing with Scala Futures Backend guy at Cloud9rs Ltd. (aka Senior Software Engineer) [email protected] twitter.com/tamer_radi (few tweets, if any!)

Transcript of Cw13 playing with scala by tamer abdelradi

Page 1: Cw13 playing with scala by tamer abdelradi

Play-ing with Scala Futures

Backend guy at Cloud9rs Ltd.(aka Senior Software Engineer)

[email protected]/tamer_radi (few tweets, if any!)

Page 2: Cw13 playing with scala by tamer abdelradi

About Scala

Martin Odersky● He designed Java Generics● Built the javac compiler● In 2001, designed Scala● In 2011, he founded

Typesafe Inc., a company to support and promote Scala

Page 3: Cw13 playing with scala by tamer abdelradi

Who Uses Scala

More: http://www.scala-lang.org/node/1658

Page 4: Cw13 playing with scala by tamer abdelradi

Why Scala

Can borrow from Java (runs on JVM)Concise

Very OOP, Very FunctionalStatically type, but with type inference.Lazy values

class Rectangle(val w: Int, val l: Int)class Square(s: Int) extends Rectangle(s, s)

Page 5: Cw13 playing with scala by tamer abdelradi

Why Scala - Traits

Traits for cross-cutting modularityLike Interfaces, but with implementation

class Man { def walk() {....} } trait SuperPowers { def fly() {....} }

class SuperMan extends Man with SuperPowers val superMan = new SuperMan

val superMan = new Man with SuperPowers

object SuperMan extends Man with SuperPowers { def doLaserAndStuff() { ... } }

Page 6: Cw13 playing with scala by tamer abdelradi

Why Scala - Concurrency

Parallel Collections (1 to 10000).par.map(_ * 2).reduce(_ + _) Note: reduce operation is not ordered

Futures future { slowOperation() } foreach println println("Hey, I don't have to wait")

Akka Actors (http://akka.io)

Page 7: Cw13 playing with scala by tamer abdelradi

Play Framework

Stateless (easy to scale)Built on AkkaNon-blocking I/O (uses JBoss Netty)Real-time & Streaming are First Class Citizins Websockets EventSource CometProduction support by TypesafeMany cloud deployment options

Page 8: Cw13 playing with scala by tamer abdelradi

Now Let's Code..

The code is available onhttps://github.com/tabdulradi/weather