LSUG: How we (mostly) moved from Java to Scala

Graham Tackley
Graham Tackleyguardian.co.uk
(mostly)

How we moved from
         ^

   Java to Scala
     Graham Tackley
     guardian.co.uk
History

• Java shop since 2006
• guardian.co.uk: java + spring + velocity +
  hibernate + oracle
• ~100k lines production java code (and
  ~35k xml...)
Content API
• Provide API to access all of our website
  content
• Limited beta released early 2009
• Started implementation of final version late
  2009
• Live May 2010:
  http://content.guardianapis.com
Content API


(demo of http://content.guardianapis.com)
November 2009


• Started new Content API implementation
• java + guice + guice servlets + apache solr
November 2009


• A few people had played with scala
• No production scala code
January 2010
• Comprehensive integration tests were very
  important to us
• Started writing our integration tests in
  Scala with the awesome ScalaTest
• Already a maven project, so mixed scala-
  java support easy with maven-scala-plugin


                                             demo: mavan-scala-plugin, ScalaTest
January 2010
January 2010


• A fair bit of our test code was java-
  without-semicolons as we learnt about
  Scala...
January 2010
February 2010

• ... despite that we loved it so much that
  after a month we decided to convert the
  whole app to Scala
• scala + guice + guice servlets + apache solr
February 2010




Still some very java-like code...
February 2010




... immediate win with non-IDE generated constructors ...
February 2010




... and some things much more readable than Java
Our top 5 things we
 loved about scala
    on day one
1. Sensible Class Constructors



             =>
2. Type inference / val & var

List<String> myList = new ArrayList<String>();



                      =>

import java.util.ArrayList
val myList = new ArrayList[String]
3. No source file naming
           constraints


• Don’t need to be named after package &
  class name like java
• So multiple classes are allowed in a single file


                                              e.g. ResponseRenderer.scala
4. REPL (console)



• run “scala” for a scala shell
• awesome for experimentation
5. Same tools, libs, deployment &
 runtime characteristics as Java

• We still use IntelliJ (with the scala plugin)
• A scala war file is just a war file
• All the experience of running jvm in
  production still applies
• Can still use java libraries

                                          e.g. GuiceServletConfig.scala, XmlFormatter.scala
From Day One

Sensible class constructors                                   +1

No getters & setters

val and var, implict variable typing                          +4

No filename restrictions

No need for semicolons                                        +1

Same tools, lib, depoyment, runtime characteristics as java   +1

Less { }

object keyword

decent collections library

“”” string notation

list.filter(_.test).map(_.transformation)                     +1

case classes for value object                                 +2

default parameters

regexes: .r & unapply                                         +1

it’s fun!

val => encourages immutubility

traits                                                        +2

match statements

library DSLs such as lift-json

easy maps and lists

REPL                                                          +1

write the java you know then refine

map, filter etc

Far more expressive code

Functions as first class objects
Our top 5 things we
          loved about scala
             on day one

                          SUMMARY:
Scala is great even if you only use it as a more concise java
                 (java-without-semicolons™);
             for us this was a great way to start.
July 2010

• Switched from maven to simple-build-tool
• Mainly for incremental compilation
• ~ test-quick and ~ prepare-webapp also
  invaluable
Our top 5 things we
 love about scala
   one year on
1. Option
or How we learned to stop worrying and love the Option

 We’d read “don’t use nulls, use Option instead”
                DAY ONE
               x != null
                 became
             x.isDefined
               DAY THREE
     x match {
       case None => ...
       case Some(value) => ...
     }
1. Option
    or How we learned to stop worrying and love the Option

                       WEEK THREE




                          TODAY



We now think of Options as lists with zero or one entries
2. powerful collections library




it took us a while to realise that most of the loops we
     wrote in Java were actually “map” or “flatMap”
2. powerful collections library




it took us a while to realise that most of the loops we
     wrote in Java were actually “map” or “flatMap”
3. traits as mixins



 demo: SearchRequest
4. implicit conversions to
      enhance existing classes


      Content API extensively uses Solr/J,
     which is good but returns loads of nulls



We used implicit conversions to hide the Java yuk


                                                demo: RichSolrDocument
LSUG: How we (mostly) moved from Java to Scala
5. pattern matching



    demo: UserTier
After a couple of months

Using Option properly

Functional programming - i.e. without side effects           +1

Powerful collections library

traits as mixins                                             +2

json & xml parsing & generation

implicit conversions to enhance existing classes             +2

regexes

apply and unapply methods

infix statements

learning not to overcomplicate

thinking functionally

DSLs

Actors

Rename imported classes

Extractors & pattern matching                                +1

Passing closures all

Companion object pattern

currying functions

default parameters and case class copy methods

parser combinators                                           +1

implicits and traits instead of dependency injection

partial functions

null is not an option
Summary
• Migration path from Java relatively smooth
• Take it easy, and don’t fear java-without-
  semicolons in the early days
• An incremental embrace of Scala features
  worked really well for us
• Hide the Java yuk with implicit conversions
• http://content.guardianapis.com
• http://www.guardian.co.uk/open-platform
• http://github.com/guardian/open-platform-
  content-api-scala-client
• And we’re hiring:
  http://www.gnmcareers.co.uk ref JS323
       graham.tackley@guardian.co.uk
1 of 35

Recommended

Java to Scala: Why & How by
Java to Scala: Why & HowJava to Scala: Why & How
Java to Scala: Why & HowGraham Tackley
2.9K views66 slides
Java to scala by
Java to scalaJava to scala
Java to scalaGraham Tackley
2.2K views22 slides
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca... by
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...
Scala in-practice-3-years by Patric Fornasier, Springr, presented at Pune Sca...Thoughtworks
5.1K views57 slides
From Ruby to Scala by
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
7.9K views41 slides
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう! by
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!scalaconfjp
3.2K views58 slides
Scala profiling by
Scala profilingScala profiling
Scala profilingFilippo Pacifici
12.5K views36 slides

More Related Content

What's hot

Introducing Scala to your Ruby/Java Shop : My experiences at IGN by
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGNManish Pandit
1.5K views35 slides
Using Apache Camel as AKKA by
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
6.2K views50 slides
Paws: A Perl AWS SDK - YAPC Europe 2015 by
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015CAPSiDE
982 views55 slides
Scala in practice by
Scala in practiceScala in practice
Scala in practiceTomer Gabel
25.5K views41 slides
A Brief, but Dense, Intro to Scala by
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaDerek Chen-Becker
1.7K views12 slides
Building an aws sdk for Perl - Granada Perl Workshop 2014 by
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014Jose Luis Martínez
1.3K views47 slides

What's hot(20)

Introducing Scala to your Ruby/Java Shop : My experiences at IGN by Manish Pandit
Introducing Scala to your Ruby/Java Shop : My experiences at IGNIntroducing Scala to your Ruby/Java Shop : My experiences at IGN
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit1.5K views
Using Apache Camel as AKKA by Johan Edstrom
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
Johan Edstrom6.2K views
Paws: A Perl AWS SDK - YAPC Europe 2015 by CAPSiDE
Paws: A Perl AWS SDK - YAPC Europe 2015Paws: A Perl AWS SDK - YAPC Europe 2015
Paws: A Perl AWS SDK - YAPC Europe 2015
CAPSiDE982 views
Scala in practice by Tomer Gabel
Scala in practiceScala in practice
Scala in practice
Tomer Gabel25.5K views
Building an aws sdk for Perl - Granada Perl Workshop 2014 by Jose Luis Martínez
Building an aws sdk for Perl - Granada Perl Workshop 2014Building an aws sdk for Perl - Granada Perl Workshop 2014
Building an aws sdk for Perl - Granada Perl Workshop 2014
Jose Luis Martínez1.3K views
Building Asynchronous Applications by Johan Edstrom
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
Johan Edstrom633 views
Javawug bof 57 scala why now by Skills Matter
Javawug bof 57 scala why nowJavawug bof 57 scala why now
Javawug bof 57 scala why now
Skills Matter616 views
I18nize Scala programs à la gettext by Ngoc Dao
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
Ngoc Dao2K views
System Integration with Akka and Apache Camel by krasserm
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
krasserm13.5K views
Scala for android by Tack Mobile
Scala for androidScala for android
Scala for android
Tack Mobile1.3K views
Introduction to Scala : Clueda by Andreas Neumann
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
Andreas Neumann1.2K views
Java 8 and Beyond, a Scala Story by Tomer Gabel
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
Tomer Gabel747 views
Apache Camel Introduction & What's in the box by Claus Ibsen
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen4.8K views
Event Driven Architecture with Apache Camel by prajods
Event Driven Architecture with Apache CamelEvent Driven Architecture with Apache Camel
Event Driven Architecture with Apache Camel
prajods7.1K views
Akka-chan's Survival Guide for the Streaming World by Konrad Malawski
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
Konrad Malawski5.4K views

Similar to LSUG: How we (mostly) moved from Java to Scala

Java to scala by
Java to scalaJava to scala
Java to scalaGiltTech
769 views25 slides
Scala final ppt vinay by
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
227 views66 slides
Scala Introduction by
Scala IntroductionScala Introduction
Scala IntroductionAdrian Spender
3.2K views76 slides
An Introduction to Scala by
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
1.7K views25 slides
Introduction to Scala by
Introduction to ScalaIntroduction to Scala
Introduction to ScalaMohammad Hossein Rimaz
5.8K views83 slides
Java basics at Lara Technologies by
Java basics at Lara TechnologiesJava basics at Lara Technologies
Java basics at Lara Technologieslaratechnologies
736 views12 slides

Similar to LSUG: How we (mostly) moved from Java to Scala(20)

Java to scala by GiltTech
Java to scalaJava to scala
Java to scala
GiltTech769 views
Scala final ppt vinay by Viplav Jain
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
Viplav Jain227 views
An Introduction to Scala by Brent Lemons
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
Brent Lemons1.7K views
Java Closures by Ben Evans
Java ClosuresJava Closures
Java Closures
Ben Evans1.8K views
Scala, Play 2.0 & Cloud Foundry by Pray Desai
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai3.3K views
Develop realtime web with Scala and Xitrum by Ngoc Dao
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao42.5K views
A Tour Of Scala by fanf42
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
fanf423.4K views
The Why and How of Scala at Twitter by Alex Payne
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne40.6K views
Java introduction by lara technologies by technologieslara
Java introduction by lara technologiesJava introduction by lara technologies
Java introduction by lara technologies
technologieslara170 views
Scala adoption by enterprises by Mike Slinn
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
Mike Slinn8K views
Polyglot Plugin Programming by Atlassian
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
Atlassian1.1K views
Scala, Akka, and Play: An Introduction on Heroku by Havoc Pennington
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
Havoc Pennington16.8K views
Scala in the Wild by Tomer Gabel
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel2.8K views

Recently uploaded

NTGapps NTG LowCode Platform by
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform Mustafa Kuğu
28 views30 slides
MVP and prioritization.pdf by
MVP and prioritization.pdfMVP and prioritization.pdf
MVP and prioritization.pdfrahuldharwal141
37 views8 slides
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...ShapeBlue
28 views17 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
54 views18 slides
DRBD Deep Dive - Philipp Reisner - LINBIT by
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBITShapeBlue
44 views21 slides
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...ShapeBlue
40 views25 slides

Recently uploaded(20)

NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu28 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue28 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue54 views
DRBD Deep Dive - Philipp Reisner - LINBIT by ShapeBlue
DRBD Deep Dive - Philipp Reisner - LINBITDRBD Deep Dive - Philipp Reisner - LINBIT
DRBD Deep Dive - Philipp Reisner - LINBIT
ShapeBlue44 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue40 views
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... by ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue37 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue55 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T by ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue38 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker48 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10345 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue46 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue64 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue31 views

LSUG: How we (mostly) moved from Java to Scala

  • 1. (mostly) How we moved from ^ Java to Scala Graham Tackley guardian.co.uk
  • 2. History • Java shop since 2006 • guardian.co.uk: java + spring + velocity + hibernate + oracle • ~100k lines production java code (and ~35k xml...)
  • 3. Content API • Provide API to access all of our website content • Limited beta released early 2009 • Started implementation of final version late 2009 • Live May 2010: http://content.guardianapis.com
  • 4. Content API (demo of http://content.guardianapis.com)
  • 5. November 2009 • Started new Content API implementation • java + guice + guice servlets + apache solr
  • 6. November 2009 • A few people had played with scala • No production scala code
  • 7. January 2010 • Comprehensive integration tests were very important to us • Started writing our integration tests in Scala with the awesome ScalaTest • Already a maven project, so mixed scala- java support easy with maven-scala-plugin demo: mavan-scala-plugin, ScalaTest
  • 9. January 2010 • A fair bit of our test code was java- without-semicolons as we learnt about Scala...
  • 11. February 2010 • ... despite that we loved it so much that after a month we decided to convert the whole app to Scala • scala + guice + guice servlets + apache solr
  • 12. February 2010 Still some very java-like code...
  • 13. February 2010 ... immediate win with non-IDE generated constructors ...
  • 14. February 2010 ... and some things much more readable than Java
  • 15. Our top 5 things we loved about scala on day one
  • 16. 1. Sensible Class Constructors =>
  • 17. 2. Type inference / val & var List<String> myList = new ArrayList<String>(); => import java.util.ArrayList val myList = new ArrayList[String]
  • 18. 3. No source file naming constraints • Don’t need to be named after package & class name like java • So multiple classes are allowed in a single file e.g. ResponseRenderer.scala
  • 19. 4. REPL (console) • run “scala” for a scala shell • awesome for experimentation
  • 20. 5. Same tools, libs, deployment & runtime characteristics as Java • We still use IntelliJ (with the scala plugin) • A scala war file is just a war file • All the experience of running jvm in production still applies • Can still use java libraries e.g. GuiceServletConfig.scala, XmlFormatter.scala
  • 21. From Day One Sensible class constructors +1 No getters & setters val and var, implict variable typing +4 No filename restrictions No need for semicolons +1 Same tools, lib, depoyment, runtime characteristics as java +1 Less { } object keyword decent collections library “”” string notation list.filter(_.test).map(_.transformation) +1 case classes for value object +2 default parameters regexes: .r & unapply +1 it’s fun! val => encourages immutubility traits +2 match statements library DSLs such as lift-json easy maps and lists REPL +1 write the java you know then refine map, filter etc Far more expressive code Functions as first class objects
  • 22. Our top 5 things we loved about scala on day one SUMMARY: Scala is great even if you only use it as a more concise java (java-without-semicolons™); for us this was a great way to start.
  • 23. July 2010 • Switched from maven to simple-build-tool • Mainly for incremental compilation • ~ test-quick and ~ prepare-webapp also invaluable
  • 24. Our top 5 things we love about scala one year on
  • 25. 1. Option or How we learned to stop worrying and love the Option We’d read “don’t use nulls, use Option instead” DAY ONE x != null became x.isDefined DAY THREE x match { case None => ... case Some(value) => ... }
  • 26. 1. Option or How we learned to stop worrying and love the Option WEEK THREE TODAY We now think of Options as lists with zero or one entries
  • 27. 2. powerful collections library it took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
  • 28. 2. powerful collections library it took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
  • 29. 3. traits as mixins demo: SearchRequest
  • 30. 4. implicit conversions to enhance existing classes Content API extensively uses Solr/J, which is good but returns loads of nulls We used implicit conversions to hide the Java yuk demo: RichSolrDocument
  • 32. 5. pattern matching demo: UserTier
  • 33. After a couple of months Using Option properly Functional programming - i.e. without side effects +1 Powerful collections library traits as mixins +2 json & xml parsing & generation implicit conversions to enhance existing classes +2 regexes apply and unapply methods infix statements learning not to overcomplicate thinking functionally DSLs Actors Rename imported classes Extractors & pattern matching +1 Passing closures all Companion object pattern currying functions default parameters and case class copy methods parser combinators +1 implicits and traits instead of dependency injection partial functions null is not an option
  • 34. Summary • Migration path from Java relatively smooth • Take it easy, and don’t fear java-without- semicolons in the early days • An incremental embrace of Scala features worked really well for us • Hide the Java yuk with implicit conversions
  • 35. • http://content.guardianapis.com • http://www.guardian.co.uk/open-platform • http://github.com/guardian/open-platform- content-api-scala-client • And we’re hiring: http://www.gnmcareers.co.uk ref JS323 graham.tackley@guardian.co.uk

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. Demo\n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n