SlideShare a Scribd company logo
Introducing Scala to your
     Java/Ruby Shop
      My experiences at IGN



                           Manish Pandit
                   Silicon Valley Code Camp ‘12
                            Oct 7th, 2012
About me

             Manish Pandit
      Director of Engineering, IGN
             @lobster1234

       linkedin.com/in/mpandit
About IGN
We are a leading online media and services
company
obsessed with gaming and entertainment.

56MM Monthly Unique Views
737MM Monthly Page Views
20MM Monthly Video Views
My Objective
Is:
To share my story of introducing Scala to IGN, and
(hopefully) show you the path to enlightenment.


Isn't:
To incite a functional vs. imperative, or Scala vs. ____
debate.
The IGN Tech Stack
Best tool for the job
• Front End : JS, CSS3, HTML5, backbone,
  Coffeescript, jQuery
• Middle Tier : ZF2 (PHP), Rails
• APIs : Scala, some Java
• Persistence : MongoDB, MySQL, Redis
• Search : ElasticSearch
• Caching : Memcached, Varnish
APIs at IGN : Numbers
• ~5 Billion requests a month
• Average Response time of under
  20ms on cache misses
• 17 APIs between Social, OAuth,
  and Content
• Hardest hit APIs doing about
  25K RPM at peak
The Kitchen Sink
• CMS – JSPs talking to Oracle DB and some Java
  services
• V1 API : Java Services using Oracle DB with
  Memcached
• V2 API : Rails based API layer using MongoDB and a
  Java/Memcached front cache
• Lots of duct tape like messaging and cron jobs for
  simple tasks
• Too diverse of a stack in the API infrastructure
The API Evolution : V3 [2012]
• A fresh look at the APIs and IGN’s direction
• First attempt to
  – Integrate all content types
  – Open up the APIs to external consumers
  – Evolve the CMS, traditionally a monolithic system
  – ElasticSearch
  – Varnish Response Caching
• A learning opportunity for traditional Java
  stack engineers
Roadblocks
• Resistance to change
  – Culture
  – Willingness and commitment
• Too many choices – making the right pick
  – Involve every one
  – Do not decide by committee, decide by learning
  – Time box and measure everything
  – Be accountable, as you’re looked upon as the
    expert
The hunt for…
•   A runtime as fast, if not faster than Java
•   Concise, yet expressive
•   Less boilerplate
•   Smooth learning curve and ramp up
•   Re-use ecosystem of libraries
•   Growing adoption and developer velocity
•   Built in support for concurrency
•   Fast and fun development
•   Next level of programming – disrupt!
Why Scala : Strategic Reasons
• Evolve the talent brand along side evolving
  the platform
• Establish an API platform by replacing
  “rewrite” with learning instead of porting
• Start thinking functional
• Align with the leaders in the APIs
• Get involved with a technology as it is evolving
  (vs. established). Helps with influence.
Why Scala : Tactical Reasons
• Performance tied to cores than processor
  speed, i.e. concurrency
• Ideal for API development – (relatively) simple
  to handle concurrency and immutability
• JVM based = Performance
• Re-use Java toolkits and libraries
• Concise, yet expressive code
• Actor model makes the difficult parts easy
Why Scala : Tactical Reasons
•   Richer Collections API
•   Traits enabling Mix-Ins and behavior re-use
•   Statically Typed w/Type inference
•   Functional, but not alien (it can be!)
•   REPL
Yes, Virginia, Scala is hard : DPP
So, how can you figure out if Scala will be "easy" or "hard" for your
organization:
•Your company has speakers at JavaOne, OSCON, Strangle Loop, QCon: Scala
will be easy
•Lunch-time discussions involve the criteria for moving from a developer to a
senior developer: Scala will be hard
•Your developers can write code in NotePad if they have to: Easy
•Your developers stare blankly or say 3 "Hail Marys" when they hear the
name "Zed Shaw": Scala == Hard
•Developers all follow Dean Wampler on Twitter: Scala Easy
•Your developers come in at 9:15 and leave before 6 and don't check work
email at night: Hard

   http://blog.goodstuff.im/yes-virginia-scala-is-hard
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Picking up Scala : Week 1
• Scala for Java Developers fast-tracked the
  learning
• Syntax Familiarity
• Java without semicolons?
     def total(nums: List[Int]) :Int = {
       var sum:Int=0
       for(num<-nums) {
         sum+=num
       }
       sum
     }
Picking up Scala : Week 4
• Reduce the lines of code, embrace
  immutability, use the functional paradigms
  built into the language
• Unmystrify the implicits magic
    nums.foldLeft(0)((n,c) => n+c)
Picking up Scala : Today
• Focus on immutability
• Think functional – with the knowledge gained
  from using the functional aspects of the
  language, build control abstractions
• Explore and implement ScalaZ
• Keep learning, and applying
• Move all the Actor processing to Akka
Less Boilerplate
  public class HelloWorld{
     public static void main(String... args){
           System.out.println("Hello, World!");
     }
  }

  object HelloWorld extends App{
     println("Hello, World!")
  }

  scala> println("Hello, World!")
Expressive, yet concise
  val x = if(n%2==0) "Even" else "Odd"

  val x = for(i <- 1 to 10) yield i*2

  val x = for(i <- 1 to 10; if(i%2==0)) yield i*2

  val y = 20 match{
     case p if(p%2==0) => "Even"
     case _ => "Odd"
  }

  val largest = List(1,5,2,6).foldLeft(0)((a,b)=> if(a>b)
  a else b)
Less pain points
  No more dreaded null or throwing unwanted exceptions :
  Use Option[T]

  def thisMayReturnNull[T](x:T):Option[T]={
     if(true) Some(x) else None
  }


  No more creating classes only to return more than 1 value :
  Use Tuples

  def doublePair(x:Int)= (x,x*2)
Try-catch mess
try{
       //Construct a URL which can throw a MalformedURLException
       //do something with a URL which can throw IOException
       //do something with string encoding which can throw
       // UnsupportedEncodingException
 } catch{
   case mal:MalformedURLException => //something
   case ioe: IOException => //something
   case e: Exception => //something
 }
Type Inference
scala> val x = "Sunday"
x: java.lang.String = Sunday

scala> def x(n:Int) = n*3
x: (n: Int)Int

scala> 1 to 5
res2: scala.collection.immutable.Range.Inclusive =
Range(1, 2, 3, 4, 5)

scala> def x = if(true) Left("Yes!") else Right(new
Exception("Didn’t work out!"))
x: Product with Serializable with
Either[java.lang.String,java.lang.Exception]
Dynamic Mix-ins
class Home(bedrooms:Int=3,bathrooms:Double=2.5)

trait Garage{
  def park(n:Int) = println("Parking " + n + "cars")
}

val someHome = new Home

val someHomeWithGarage = new Home with Garage

someHomeWithGarage.park(2)
Concurrency
• Actors make concurrency so much easier
  – Messaging vs. Blocking
  – Lightweight, 300-500 bytes per instance
  – Isolated
Scala API Components
•   Scalatra
•   Lift-MongoRecord for MongoDB
•   Casbah for MongoDB
•   PlayFramework 2
•   Actors for tasks like syndication
•   sbt and Maven for Builds
•   MongoDB for persistence
Other API Components
•   Varnish Cache
•   Elasticsearch
•   Yammer Metrics (ping, healthcheck)
•   Swagger (self-documenting RESTful APIs)
•   3Scale for Partner APIs
•   IntelliJ IDEA and Eclipse with ScalaIDE
•   PlayFramework 2.0 (New!)
•   ScalaTest for Testing
Challenges with Scala                             *


• Steepness of the Learning curve depends
  entirely on your org culture
• Scala is what you make of it
   • http://scalaz.github.com/scalaz/scalaz-2.9.1-
     6.0.4/doc.sxr/scalaz/BKTree.scala.html

   • Middle Ground between Simplicity and,
     well..elegance



* None of these challenges outweigh the benefits. They’re just something to
be aware of.
Challenges with Scala
• Slow compilation based on the source
• No (binary) compatibility of dependencies for
  the major releases (2.8, 2.9, 2.10(?))
• Tooling not as rich as Java
  – Changing (rapidly) with Typesafe investing in
    ScalaIDE
  – ScalaIDE comes with a Scala Worksheet, which is
    like REPL but richer
Lessons Learned : Culture
• Culture of Meetups, Hack
  Nights and Code Jams
• Being able to connect with
  the contributors and
  language creators
• Willingness to invest in
  learning, evolving vs.
  maintaining
Lessons Learned : Team
•   Small team (~5 engineers)
•   Java background helped a lot
•   10% time set aside for skill building
•   Learn and share
•   It is a commitment
•   Communication!
Lessons Learned : Material
• Books that have exercises, so you
  can quantify your learning.
• Online tutorials
• StackOverflow
• Coursera : A course on Functional
  Programming by Martin Odersky
Resources
• Books
   – Programming in Scala by Odersky
   – Scala for the Impatient by Horstmann
• Interwebz
   – http://debasishg.blogspot.com
   – http://www.reddit.com/r/scala
   – http://stackoverflow.com/tags/scala/info
   – http://twitter.github.com/scala_school
   – https://www.coursera.org/course/progfun
scala> case class Me(name:String="Manish
Pandit",twitter:String="@lobster1234")
defined class Me

scala> val me = new Me
me: Me = Me(Manish Pandit,@lobster1234)

scala> println(“Questions!”)
Questions!

More Related Content

KEY
LSUG: How we (mostly) moved from Java to Scala
PPT
Sbt, idea and eclipse
PDF
Java 8 and Beyond, a Scala Story
PDF
[A4]de view2012 scala-michinisougu
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
PDF
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
PDF
Scala in a nutshell
ODP
Refactoring to Scala DSLs and LiftOff 2009 Recap
LSUG: How we (mostly) moved from Java to Scala
Sbt, idea and eclipse
Java 8 and Beyond, a Scala Story
[A4]de view2012 scala-michinisougu
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
Scala in a nutshell
Refactoring to Scala DSLs and LiftOff 2009 Recap

What's hot (20)

PDF
Scala for android
PDF
A Brief, but Dense, Intro to Scala
PDF
From Java to Ruby...and Back
PDF
Java 8 selected updates
PDF
Functional Programming with Immutable Data Structures
PPT
The Economies of Scaling Software
PPTX
Java 101 intro to programming with java
PPTX
Java unit1 a- History of Java to string
ODP
Scala's evolving ecosystem- Introduction to Scala.js
PPTX
PROGRAMMING IN JAVA- unit 4-part II
PDF
Develop realtime web with Scala and Xitrum
PPTX
Java 101 Intro to Java Programming
PPTX
Java basics at Lara Technologies
PDF
Ruby and Rails short motivation
PDF
The Dark Art of Rails Plugins (2008)
PDF
The New JavaScript: ES6
PDF
Polyglot Plugin Programming
PDF
JScala. Write your JavaScript in Scala
PPTX
PROGRAMMING IN JAVA- unit 5-part II
PDF
Scala: An OO Surprise
Scala for android
A Brief, but Dense, Intro to Scala
From Java to Ruby...and Back
Java 8 selected updates
Functional Programming with Immutable Data Structures
The Economies of Scaling Software
Java 101 intro to programming with java
Java unit1 a- History of Java to string
Scala's evolving ecosystem- Introduction to Scala.js
PROGRAMMING IN JAVA- unit 4-part II
Develop realtime web with Scala and Xitrum
Java 101 Intro to Java Programming
Java basics at Lara Technologies
Ruby and Rails short motivation
The Dark Art of Rails Plugins (2008)
The New JavaScript: ES6
Polyglot Plugin Programming
JScala. Write your JavaScript in Scala
PROGRAMMING IN JAVA- unit 5-part II
Scala: An OO Surprise
Ad

Viewers also liked (20)

PPT
Acacia Research and Learning Forum Tutorial 2
DOC
πώςθα δημιουργήσετε ένα σενάριο διδασκαλίας
PDF
ΦΕΚ ΔΙΔΑΣΚΑΛΙΑΣ ΤΗΣ ΦΥΣΙΚΗΣ Α ΛΥΚΕΙΟΥ 2011-12 διδασκαλιασ τησ φυσικησ α λυκειου
PPTX
Political Cartoons
 
PPT
LSAS mokymai
PDF
Katechismus 11 - 12 jarigen - De Tien Geboden
PPT
Onlinetools&amp;Job Search2010
ODP
Programming Ruby On Rails
PPTX
Knowwi Intro 2010
PDF
Katechismus 11 - 12 jarigen - De Geloofsbelijdenis
PPT
PDF
Pp Kee Dome Web
PDF
Future Agenda Future Of Energy
PPT
Evolving IGN’s New APIs with Scala
PPTX
Photo Album
PPT
Research writing introduction
PDF
Makeup Consultations & Professional Makeup: A Beautiful Education
PPTX
Danish mediaassoc conf 2014 (condenast)
PDF
ThirdSpace: orchestrating collaborative activities in PLEs for formal learning
Acacia Research and Learning Forum Tutorial 2
πώςθα δημιουργήσετε ένα σενάριο διδασκαλίας
ΦΕΚ ΔΙΔΑΣΚΑΛΙΑΣ ΤΗΣ ΦΥΣΙΚΗΣ Α ΛΥΚΕΙΟΥ 2011-12 διδασκαλιασ τησ φυσικησ α λυκειου
Political Cartoons
 
LSAS mokymai
Katechismus 11 - 12 jarigen - De Tien Geboden
Onlinetools&amp;Job Search2010
Programming Ruby On Rails
Knowwi Intro 2010
Katechismus 11 - 12 jarigen - De Geloofsbelijdenis
Pp Kee Dome Web
Future Agenda Future Of Energy
Evolving IGN’s New APIs with Scala
Photo Album
Research writing introduction
Makeup Consultations & Professional Makeup: A Beautiful Education
Danish mediaassoc conf 2014 (condenast)
ThirdSpace: orchestrating collaborative activities in PLEs for formal learning
Ad

Similar to Introducing Scala to your Ruby/Java Shop : My experiences at IGN (20)

PPTX
Scala final ppt vinay
PDF
Scala and jvm_languages_praveen_technologist
PPTX
Scala in practice
PPTX
Spark - The Ultimate Scala Collections by Martin Odersky
PPTX
Introduction to Scala
PPTX
Scala-Ls1
PDF
Martin Odersky: What's next for Scala
PPTX
An Introduction to Scala
PPTX
Scala in the Wild
KEY
Scala Introduction
KEY
Polyglot and Functional Programming (OSCON 2012)
KEY
The Why and How of Scala at Twitter
PDF
Quick introduction to scala
PDF
Java 8 features
PDF
Building DSLs with Scala
PPTX
Scala Italy 2015 - Hands On ScalaJS
PPTX
Alberto Paro - Hands on Scala.js
PDF
Functional Scala 2022 - scalajs Alexis.pdf
PDF
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
PPTX
Scala adoption by enterprises
Scala final ppt vinay
Scala and jvm_languages_praveen_technologist
Scala in practice
Spark - The Ultimate Scala Collections by Martin Odersky
Introduction to Scala
Scala-Ls1
Martin Odersky: What's next for Scala
An Introduction to Scala
Scala in the Wild
Scala Introduction
Polyglot and Functional Programming (OSCON 2012)
The Why and How of Scala at Twitter
Quick introduction to scala
Java 8 features
Building DSLs with Scala
Scala Italy 2015 - Hands On ScalaJS
Alberto Paro - Hands on Scala.js
Functional Scala 2022 - scalajs Alexis.pdf
JavaOne 2017 - Collections.compare:JDK, Eclipse, Guava, Apache... [CON1754]
Scala adoption by enterprises

More from Manish Pandit (20)

PDF
Disaster recovery - What, Why, and How
PDF
Serverless Architectures on AWS in practice - OSCON 2018
PDF
Disaster Recovery and Reliability
PDF
OAuth2 primer
PDF
Immutable AWS Deployments with Packer and Jenkins
PDF
AWS Lambda with Serverless Framework and Java
PDF
AWS Primer and Quickstart
PPTX
Securing your APIs with OAuth, OpenID, and OpenID Connect
PDF
Silicon Valley 2014 - API Antipatterns
PDF
Scalabay - API Design Antipatterns
PDF
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
PPTX
API Design Antipatterns - APICon SF
PPTX
Motivation : it Matters
PPTX
Building Apis in Scala with Playframework2
PPTX
Scala at Netflix
PPTX
IGN's V3 API
PPTX
Java and the JVM
PPTX
Object Oriented Programming
PPTX
Silicon Valley Code Camp 2011: Play! as you REST
PPTX
Silicon Valley Code Camp: 2011 Introduction to MongoDB
Disaster recovery - What, Why, and How
Serverless Architectures on AWS in practice - OSCON 2018
Disaster Recovery and Reliability
OAuth2 primer
Immutable AWS Deployments with Packer and Jenkins
AWS Lambda with Serverless Framework and Java
AWS Primer and Quickstart
Securing your APIs with OAuth, OpenID, and OpenID Connect
Silicon Valley 2014 - API Antipatterns
Scalabay - API Design Antipatterns
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
API Design Antipatterns - APICon SF
Motivation : it Matters
Building Apis in Scala with Playframework2
Scala at Netflix
IGN's V3 API
Java and the JVM
Object Oriented Programming
Silicon Valley Code Camp 2011: Play! as you REST
Silicon Valley Code Camp: 2011 Introduction to MongoDB

Recently uploaded (20)

PDF
Electronic commerce courselecture one. Pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Spectroscopy.pptx food analysis technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Electronic commerce courselecture one. Pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
Network Security Unit 5.pdf for BCA BBA.
A comparative analysis of optical character recognition models for extracting...
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Spectroscopy.pptx food analysis technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine Learning_overview_presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Introducing Scala to your Ruby/Java Shop : My experiences at IGN

  • 1. Introducing Scala to your Java/Ruby Shop My experiences at IGN Manish Pandit Silicon Valley Code Camp ‘12 Oct 7th, 2012
  • 2. About me Manish Pandit Director of Engineering, IGN @lobster1234 linkedin.com/in/mpandit
  • 3. About IGN We are a leading online media and services company obsessed with gaming and entertainment. 56MM Monthly Unique Views 737MM Monthly Page Views 20MM Monthly Video Views
  • 4. My Objective Is: To share my story of introducing Scala to IGN, and (hopefully) show you the path to enlightenment. Isn't: To incite a functional vs. imperative, or Scala vs. ____ debate.
  • 5. The IGN Tech Stack
  • 6. Best tool for the job • Front End : JS, CSS3, HTML5, backbone, Coffeescript, jQuery • Middle Tier : ZF2 (PHP), Rails • APIs : Scala, some Java • Persistence : MongoDB, MySQL, Redis • Search : ElasticSearch • Caching : Memcached, Varnish
  • 7. APIs at IGN : Numbers • ~5 Billion requests a month • Average Response time of under 20ms on cache misses • 17 APIs between Social, OAuth, and Content • Hardest hit APIs doing about 25K RPM at peak
  • 8. The Kitchen Sink • CMS – JSPs talking to Oracle DB and some Java services • V1 API : Java Services using Oracle DB with Memcached • V2 API : Rails based API layer using MongoDB and a Java/Memcached front cache • Lots of duct tape like messaging and cron jobs for simple tasks • Too diverse of a stack in the API infrastructure
  • 9. The API Evolution : V3 [2012] • A fresh look at the APIs and IGN’s direction • First attempt to – Integrate all content types – Open up the APIs to external consumers – Evolve the CMS, traditionally a monolithic system – ElasticSearch – Varnish Response Caching • A learning opportunity for traditional Java stack engineers
  • 10. Roadblocks • Resistance to change – Culture – Willingness and commitment • Too many choices – making the right pick – Involve every one – Do not decide by committee, decide by learning – Time box and measure everything – Be accountable, as you’re looked upon as the expert
  • 11. The hunt for… • A runtime as fast, if not faster than Java • Concise, yet expressive • Less boilerplate • Smooth learning curve and ramp up • Re-use ecosystem of libraries • Growing adoption and developer velocity • Built in support for concurrency • Fast and fun development • Next level of programming – disrupt!
  • 12. Why Scala : Strategic Reasons • Evolve the talent brand along side evolving the platform • Establish an API platform by replacing “rewrite” with learning instead of porting • Start thinking functional • Align with the leaders in the APIs • Get involved with a technology as it is evolving (vs. established). Helps with influence.
  • 13. Why Scala : Tactical Reasons • Performance tied to cores than processor speed, i.e. concurrency • Ideal for API development – (relatively) simple to handle concurrency and immutability • JVM based = Performance • Re-use Java toolkits and libraries • Concise, yet expressive code • Actor model makes the difficult parts easy
  • 14. Why Scala : Tactical Reasons • Richer Collections API • Traits enabling Mix-Ins and behavior re-use • Statically Typed w/Type inference • Functional, but not alien (it can be!) • REPL
  • 15. Yes, Virginia, Scala is hard : DPP So, how can you figure out if Scala will be "easy" or "hard" for your organization: •Your company has speakers at JavaOne, OSCON, Strangle Loop, QCon: Scala will be easy •Lunch-time discussions involve the criteria for moving from a developer to a senior developer: Scala will be hard •Your developers can write code in NotePad if they have to: Easy •Your developers stare blankly or say 3 "Hail Marys" when they hear the name "Zed Shaw": Scala == Hard •Developers all follow Dean Wampler on Twitter: Scala Easy •Your developers come in at 9:15 and leave before 6 and don't check work email at night: Hard http://blog.goodstuff.im/yes-virginia-scala-is-hard
  • 17. Picking up Scala : Week 1 • Scala for Java Developers fast-tracked the learning • Syntax Familiarity • Java without semicolons? def total(nums: List[Int]) :Int = { var sum:Int=0 for(num<-nums) { sum+=num } sum }
  • 18. Picking up Scala : Week 4 • Reduce the lines of code, embrace immutability, use the functional paradigms built into the language • Unmystrify the implicits magic nums.foldLeft(0)((n,c) => n+c)
  • 19. Picking up Scala : Today • Focus on immutability • Think functional – with the knowledge gained from using the functional aspects of the language, build control abstractions • Explore and implement ScalaZ • Keep learning, and applying • Move all the Actor processing to Akka
  • 20. Less Boilerplate public class HelloWorld{ public static void main(String... args){ System.out.println("Hello, World!"); } } object HelloWorld extends App{ println("Hello, World!") } scala> println("Hello, World!")
  • 21. Expressive, yet concise val x = if(n%2==0) "Even" else "Odd" val x = for(i <- 1 to 10) yield i*2 val x = for(i <- 1 to 10; if(i%2==0)) yield i*2 val y = 20 match{ case p if(p%2==0) => "Even" case _ => "Odd" } val largest = List(1,5,2,6).foldLeft(0)((a,b)=> if(a>b) a else b)
  • 22. Less pain points No more dreaded null or throwing unwanted exceptions : Use Option[T] def thisMayReturnNull[T](x:T):Option[T]={ if(true) Some(x) else None } No more creating classes only to return more than 1 value : Use Tuples def doublePair(x:Int)= (x,x*2)
  • 23. Try-catch mess try{ //Construct a URL which can throw a MalformedURLException //do something with a URL which can throw IOException //do something with string encoding which can throw // UnsupportedEncodingException } catch{ case mal:MalformedURLException => //something case ioe: IOException => //something case e: Exception => //something }
  • 24. Type Inference scala> val x = "Sunday" x: java.lang.String = Sunday scala> def x(n:Int) = n*3 x: (n: Int)Int scala> 1 to 5 res2: scala.collection.immutable.Range.Inclusive = Range(1, 2, 3, 4, 5) scala> def x = if(true) Left("Yes!") else Right(new Exception("Didn’t work out!")) x: Product with Serializable with Either[java.lang.String,java.lang.Exception]
  • 25. Dynamic Mix-ins class Home(bedrooms:Int=3,bathrooms:Double=2.5) trait Garage{ def park(n:Int) = println("Parking " + n + "cars") } val someHome = new Home val someHomeWithGarage = new Home with Garage someHomeWithGarage.park(2)
  • 26. Concurrency • Actors make concurrency so much easier – Messaging vs. Blocking – Lightweight, 300-500 bytes per instance – Isolated
  • 27. Scala API Components • Scalatra • Lift-MongoRecord for MongoDB • Casbah for MongoDB • PlayFramework 2 • Actors for tasks like syndication • sbt and Maven for Builds • MongoDB for persistence
  • 28. Other API Components • Varnish Cache • Elasticsearch • Yammer Metrics (ping, healthcheck) • Swagger (self-documenting RESTful APIs) • 3Scale for Partner APIs • IntelliJ IDEA and Eclipse with ScalaIDE • PlayFramework 2.0 (New!) • ScalaTest for Testing
  • 29. Challenges with Scala * • Steepness of the Learning curve depends entirely on your org culture • Scala is what you make of it • http://scalaz.github.com/scalaz/scalaz-2.9.1- 6.0.4/doc.sxr/scalaz/BKTree.scala.html • Middle Ground between Simplicity and, well..elegance * None of these challenges outweigh the benefits. They’re just something to be aware of.
  • 30. Challenges with Scala • Slow compilation based on the source • No (binary) compatibility of dependencies for the major releases (2.8, 2.9, 2.10(?)) • Tooling not as rich as Java – Changing (rapidly) with Typesafe investing in ScalaIDE – ScalaIDE comes with a Scala Worksheet, which is like REPL but richer
  • 31. Lessons Learned : Culture • Culture of Meetups, Hack Nights and Code Jams • Being able to connect with the contributors and language creators • Willingness to invest in learning, evolving vs. maintaining
  • 32. Lessons Learned : Team • Small team (~5 engineers) • Java background helped a lot • 10% time set aside for skill building • Learn and share • It is a commitment • Communication!
  • 33. Lessons Learned : Material • Books that have exercises, so you can quantify your learning. • Online tutorials • StackOverflow • Coursera : A course on Functional Programming by Martin Odersky
  • 34. Resources • Books – Programming in Scala by Odersky – Scala for the Impatient by Horstmann • Interwebz – http://debasishg.blogspot.com – http://www.reddit.com/r/scala – http://stackoverflow.com/tags/scala/info – http://twitter.github.com/scala_school – https://www.coursera.org/course/progfun
  • 35. scala> case class Me(name:String="Manish Pandit",twitter:String="@lobster1234") defined class Me scala> val me = new Me me: Me = Me(Manish Pandit,@lobster1234) scala> println(“Questions!”) Questions!

Editor's Notes

  • #2: ----- Meeting Notes (10/4/12 16:32) ----- Scala in production? Playing around with Scala?