SlideShare a Scribd company logo
1 of 66
HOW WE MOVED FROM
  JAVA TO SCALA
    Graham Tackley
     guardian.co.uk
       @tackers
mo stly
HOW WE MOVED FROM
  JAVA^TO SCALA

    Graham Tackley
     guardian.co.uk
       @tackers
History
• Java shop since 2006
• guardian.co.uk: java + spring + velocity +
  hibernate + oracle
History
• Java shop since 2006
• guardian.co.uk: java + spring + velocity +
  hibernate + oracle
• ~100k lines production java code
History
• Java shop since 2006
• guardian.co.uk: java + spring + velocity +
  hibernate + oracle
• ~100k lines production java code
• ~45k lines in velocity templates
History
• Java shop since 2006
• guardian.co.uk: java + spring + velocity +
  hibernate + oracle
• ~100k lines production java code
• ~45k lines in velocity templates
• ... and ~35k xml
The Reality

• This code base still lives!
• We can still enhance and improve
• We still release (at least) every two weeks
The Reality

• This code base still lives!
• We can still enhance and improve
• We still release (at least) every two weeks

                   BUT
The Java “BUT”

• Want to innovate faster
• Lots of code in current solution...
• ... takes a while to do what should be simple
  things ...
• ... and often solving a problem once or
  twice removed from the actual problem
We tried an
alternative...
Python + Django
• Easy to learn
• Great web-focused framework, so most
  things we wanted were out of the box
• Really good documentation & web support
Python + Django
• Easy to learn
• Great web-focused framework, so most
  things we wanted were out of the box
• Really good documentation & web support

                 BUT
The Python “BUT”
The Python “BUT”
• Had to throw away years of java experience
The Python “BUT”
• Had to throw away years of java experience
• Dev environment totally different
  (virtualenv, testing, ci, packaging...)
The Python “BUT”
• Had to throw away years of java experience
• Dev environment totally different
  (virtualenv, testing, ci, packaging...)
• Runtime behaviour totally different
  (mod_wsgi, pgbouncer...)
The Python “BUT”
• Had to throw away years of java experience
• Dev environment totally different
  (virtualenv, testing, ci, packaging...)
• Runtime behaviour totally different
  (mod_wsgi, pgbouncer...)
• Diagnostic tools totally different (stats
  capture, heap dumps, stack dumps, logging...)
The Python “BUT”
• Had to throw away years of java experience
• Dev environment totally different
  (virtualenv, testing, ci, packaging...)
• Runtime behaviour totally different
  (mod_wsgi, pgbouncer...)
• Diagnostic tools totally different (stats
  capture, heap dumps, stack dumps, logging...)
• More moving parts (e.g. redis where we’d
  use singletons on the jvm)
The Python “BUT”

• We lost as much (if not more) time
  operationally as we saved in development
  time
• For us, switching platform simply did not
  make sense
Is there a Third Way?
Is there a Third Way?
Is there a Third Way?
Is there a Third Way?




Scala is a statically typed, compiled language
              running on the jvm
    that “feels” like a dynamic language.
What’s so good
 about Scala?
Same tools, libs, deployment &
  runtime characteristics as Java

• We still use IntelliJ (with the scala plugin)
• It’s just bytecode
• All the experience of running jvm in
  production still applies
• Can still use java libraries
Mixed Scala-Java Projects Work


• Scala compiler can parse java, so can have
  one project containing both java & scala...
• ... with bi-directional dependencies
• We use this extensively to get the benefits of
  scala without big bang porting
Much less verbose



       =>
Type inference

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


                           =>

val myList = new ArrayList[String]
Console / REPL



• Encourages ipython / irb attitude
• Awesome for experimentation and
  exploration
Powerful collections library
Our First Scala Project:
    Content API
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
2009         2010                   2011

Nov




  • Started implementation
  • java + guice + guice servlets + apache solr
  • 3-4 java devs
2009         2010                  2011

Nov




 • A few people had played with scala
 • No production scala code
2009          2010                    2011

       Jan




 • Integration tests with ScalaTest
 • maven-scala-plugin
2009         2010   2011

       Jan
2009          2010                   2011

       Jan




 A fair bit of our test code was java-without-
 semicolons as we learnt about Scala...
2009          2010                   2011

       Jan




 A fair bit of our test code was java-without-
 semicolons as we learnt about Scala...
2009            2010                   2011

         Feb




 ... despite that we loved it so much that after a
 month we decided to convert the whole app to
 Scala


       java + guice + guice servlets + apache solr
2009           2010                   2011

       Feb




 ... 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
2009         2010           2011

       May




                    Live!
2009         2010                     2011

               Jul




 Switched from maven to simple-build-tool
 Mainly for incremental compilation
2009         2010                    2011

                                      Jul



   scala + guice + guice servlets + apache solr
2009          2010                   2011

                                         Jul



            scala + lift + apache solr




 5k loc => 3.5k (mostly due to writing better scala)
2009           2010                 2011

                                               Today



 • Scala used by default on all new jvm-based
   projects
 • Still do some (externally-hosted) new things
   in python
 • Team of 20 ex-java devs all audibly groan
   when working on java rather than scala
The Scala “BUT”?
The Scala “BUT”?

But, isn’t Scala really
      complex?
The Scala “BUT”?




    This example taken from Cay Horstmann
http://weblogs.java.net/blog/cayhorstmann/archive/2011/10/05/javaone-2011-
                                    day-3
The Four Scala
Features That Scare Java
     Developers...
The Four Scala
Features That Scare Java
     Developers...

  ... can all be explained in one slide each
Symbolic method
          names

class Complex(real: Double, imag: Double) {
 def +(other: Complex) = ....
}
Infix & Postfix
           Operations
• obj.op(x) can be written obj op x
• obj.op can be written obj op
Infix & Postfix
           Operations
• obj.op(x) can be written obj op x
• obj.op can be written obj op
     So given:
      val a = new Complex(1, 3)
      val b = new Complex(3, 4)
     Can write:
      a.+(b)
     as
      a+b
Higher order functions
scala> def apply(f: Int => Int, v: Int) = f(v)
apply: (f: Int => Int, v: Int)Int

scala> apply(i => i * 2, 7)
res1: Int = 14
Higher order functions
scala> def apply(f: Int => Int, v: Int) = f(v)
apply: (f: Int => Int, v: Int)Int

scala> apply(i => i * 2, 7)
res1: Int = 14

scala> apply(_ * 2, 7)
res2: Int = 14
Higher order functions (ii)
// Java 
Integer run(Callable<Integer> fn) throws Exception {
  return fn.call();
 }

 Integer processInt(final Integer i) throws Exception {
  return run(new Callable<Integer>() {
         public Integer call() throws Exception {
           return i + 1;
         }
     });
}
Higher order functions (ii)
// Java 
Integer run(Callable<Integer> fn) throws Exception {
  return fn.call();
 }

 Integer processInt(final Integer i) throws Exception {
  return run(new Callable<Integer>() {
         public Integer call() throws Exception {
           return i + 1;
         }
     });
}




// Scala
def run(f: => Int) = f
def processInt(i: Int) = run(i + 1)
Implicit Conversion

• given an in-scope declaration
  implicit def conv(a: A): B
• “conv” will be called whenever you have an A
  and need a B
• or you call a method on an instance of A that
  doesn’t exist on A but does on B
Writing Good Scala
Writing Good Scala


• Express your Intent. Simply.
Writing Good Scala


• Express your Intent. Simply.
• The pram is full of toys.
  Use only to achieve the above.
Demo
Summary
• Smooth migration path from Java
• Take it easy, and don’t fear java-without-
  semicolons in the early days
• You’ll lose if you stay there though!
• Incrementally embrace Scala features to
  increase readability
• Expect to keep learning
• http://content.guardianapis.com
• http://www.guardian.co.uk/open-platform
• http://github.com/guardian/open-platform-
  content-api-scala-client


 graham.tackley@guardian.co.uk ■ @tackers

More Related Content

What's hot

Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala languageAaqib Pervaiz
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Metosin Oy
 
Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Konrad Malawski
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : CluedaAndreas Neumann
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...Leonardo De Moura Rocha Lima
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettextNgoc Dao
 
Scala for android
Scala for androidScala for android
Scala for androidTack Mobile
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryTomer Gabel
 
Javawug bof 57 scala why now
Javawug bof 57 scala why nowJavawug bof 57 scala why now
Javawug bof 57 scala why nowSkills Matter
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMatt Butcher
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformEastBanc Tachnologies
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with KotlinHaim Yadid
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM languageAndrius Klimavicius
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with AkkaNgoc Dao
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 

What's hot (20)

Introduction to Scala language
Introduction to Scala languageIntroduction to Scala language
Introduction to Scala language
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
 
Introduction to Scala : Clueda
Introduction to Scala : CluedaIntroduction to Scala : Clueda
Introduction to Scala : Clueda
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...
JavaOne 2017 - Choosing a NoSQL API and Database to Avoid Tombstones and Drag...
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
Scala for android
Scala for androidScala for android
Scala for android
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
 
Javawug bof 57 scala why now
Javawug bof 57 scala why nowJavawug bof 57 scala why now
Javawug bof 57 scala why now
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Building microservices with Kotlin
Building microservices with KotlinBuilding microservices with Kotlin
Building microservices with Kotlin
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
Introduction to Kotlin JVM language
Introduction to Kotlin JVM languageIntroduction to Kotlin JVM language
Introduction to Kotlin JVM language
 
Model with actors and implement with Akka
Model with actors and implement with AkkaModel with actors and implement with Akka
Model with actors and implement with Akka
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 

Viewers also liked

Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years laterpatforna
 
Origami, a monadic fold library for Scala
Origami, a monadic fold library for ScalaOrigami, a monadic fold library for Scala
Origami, a monadic fold library for ScalaEric Torreborre
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?BoldRadius Solutions
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception HandlingLemi Orhan Ergin
 

Viewers also liked (6)

Scala in practice - 3 years later
Scala in practice - 3 years laterScala in practice - 3 years later
Scala in practice - 3 years later
 
Origami, a monadic fold library for Scala
Origami, a monadic fold library for ScalaOrigami, a monadic fold library for Scala
Origami, a monadic fold library for Scala
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?Why Not Make the Transition from Java to Scala?
Why Not Make the Transition from Java to Scala?
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
Exception Handling in Scala
Exception Handling in ScalaException Handling in Scala
Exception Handling in Scala
 

Similar to Java to Scala: Why & How

Java to scala
Java to scalaJava to scala
Java to scalaGiltTech
 
Java basics at Lara Technologies
Java basics at Lara TechnologiesJava basics at Lara Technologies
Java basics at Lara Technologieslaratechnologies
 
Challenges of moving a java team to scala
Challenges of moving a java team to scalaChallenges of moving a java team to scala
Challenges of moving a java team to scalaJoão Cavalheiro
 
Scala Native: Ahead of Time
Scala Native: Ahead of TimeScala Native: Ahead of Time
Scala Native: Ahead of TimeNadav Wiener
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
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
 
Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1lisanl
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the WildTomer Gabel
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Lucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challengesLucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challengesCharlie Hull
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKAJohan Edstrom
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |ShubhamAthawane
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of JavaFu Cheng
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-finalMarcus Lagergren
 
Java introduction by lara technologies
Java introduction by lara technologiesJava introduction by lara technologies
Java introduction by lara technologiestechnologieslara
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby.toster
 

Similar to Java to Scala: Why & How (20)

Java to scala
Java to scalaJava to scala
Java to scala
 
Scala Introduction
Scala IntroductionScala Introduction
Scala Introduction
 
Java basics at Lara Technologies
Java basics at Lara TechnologiesJava basics at Lara Technologies
Java basics at Lara Technologies
 
Challenges of moving a java team to scala
Challenges of moving a java team to scalaChallenges of moving a java team to scala
Challenges of moving a java team to scala
 
Scala Native: Ahead of Time
Scala Native: Ahead of TimeScala Native: Ahead of Time
Scala Native: Ahead of Time
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
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
 
Java to scala
Java to scalaJava to scala
Java to scala
 
Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1Expanding beyond SPL -- More language support in IBM Streams V4.1
Expanding beyond SPL -- More language support in IBM Streams V4.1
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Lucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challengesLucene, Solr and java 9 - opportunities and challenges
Lucene, Solr and java 9 - opportunities and challenges
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Java notes | All Basics |
Java notes | All Basics |Java notes | All Basics |
Java notes | All Basics |
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
Lagergren jvmls-2014-final
Lagergren jvmls-2014-finalLagergren jvmls-2014-final
Lagergren jvmls-2014-final
 
Java introduction by lara technologies
Java introduction by lara technologiesJava introduction by lara technologies
Java introduction by lara technologies
 
Polyglot Grails
Polyglot GrailsPolyglot Grails
Polyglot Grails
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
Практики применения JRuby
Практики применения JRubyПрактики применения JRuby
Практики применения JRuby
 

Recently uploaded

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Java to Scala: Why & How

  • 1. HOW WE MOVED FROM JAVA TO SCALA Graham Tackley guardian.co.uk @tackers
  • 2. mo stly HOW WE MOVED FROM JAVA^TO SCALA Graham Tackley guardian.co.uk @tackers
  • 3.
  • 4. History • Java shop since 2006 • guardian.co.uk: java + spring + velocity + hibernate + oracle
  • 5. History • Java shop since 2006 • guardian.co.uk: java + spring + velocity + hibernate + oracle • ~100k lines production java code
  • 6. History • Java shop since 2006 • guardian.co.uk: java + spring + velocity + hibernate + oracle • ~100k lines production java code • ~45k lines in velocity templates
  • 7. History • Java shop since 2006 • guardian.co.uk: java + spring + velocity + hibernate + oracle • ~100k lines production java code • ~45k lines in velocity templates • ... and ~35k xml
  • 8. The Reality • This code base still lives! • We can still enhance and improve • We still release (at least) every two weeks
  • 9. The Reality • This code base still lives! • We can still enhance and improve • We still release (at least) every two weeks BUT
  • 10. The Java “BUT” • Want to innovate faster • Lots of code in current solution... • ... takes a while to do what should be simple things ... • ... and often solving a problem once or twice removed from the actual problem
  • 12. Python + Django • Easy to learn • Great web-focused framework, so most things we wanted were out of the box • Really good documentation & web support
  • 13. Python + Django • Easy to learn • Great web-focused framework, so most things we wanted were out of the box • Really good documentation & web support BUT
  • 15. The Python “BUT” • Had to throw away years of java experience
  • 16. The Python “BUT” • Had to throw away years of java experience • Dev environment totally different (virtualenv, testing, ci, packaging...)
  • 17. The Python “BUT” • Had to throw away years of java experience • Dev environment totally different (virtualenv, testing, ci, packaging...) • Runtime behaviour totally different (mod_wsgi, pgbouncer...)
  • 18. The Python “BUT” • Had to throw away years of java experience • Dev environment totally different (virtualenv, testing, ci, packaging...) • Runtime behaviour totally different (mod_wsgi, pgbouncer...) • Diagnostic tools totally different (stats capture, heap dumps, stack dumps, logging...)
  • 19. The Python “BUT” • Had to throw away years of java experience • Dev environment totally different (virtualenv, testing, ci, packaging...) • Runtime behaviour totally different (mod_wsgi, pgbouncer...) • Diagnostic tools totally different (stats capture, heap dumps, stack dumps, logging...) • More moving parts (e.g. redis where we’d use singletons on the jvm)
  • 20. The Python “BUT” • We lost as much (if not more) time operationally as we saved in development time • For us, switching platform simply did not make sense
  • 21. Is there a Third Way?
  • 22. Is there a Third Way?
  • 23. Is there a Third Way?
  • 24. Is there a Third Way? Scala is a statically typed, compiled language running on the jvm that “feels” like a dynamic language.
  • 25. What’s so good about Scala?
  • 26. Same tools, libs, deployment & runtime characteristics as Java • We still use IntelliJ (with the scala plugin) • It’s just bytecode • All the experience of running jvm in production still applies • Can still use java libraries
  • 27. Mixed Scala-Java Projects Work • Scala compiler can parse java, so can have one project containing both java & scala... • ... with bi-directional dependencies • We use this extensively to get the benefits of scala without big bang porting
  • 29. Type inference ArrayList<String> myList = new ArrayList<String>(); => val myList = new ArrayList[String]
  • 30. Console / REPL • Encourages ipython / irb attitude • Awesome for experimentation and exploration
  • 32. Our First Scala Project: Content API
  • 33. 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
  • 34.
  • 35. 2009 2010 2011 Nov • Started implementation • java + guice + guice servlets + apache solr • 3-4 java devs
  • 36. 2009 2010 2011 Nov • A few people had played with scala • No production scala code
  • 37. 2009 2010 2011 Jan • Integration tests with ScalaTest • maven-scala-plugin
  • 38. 2009 2010 2011 Jan
  • 39. 2009 2010 2011 Jan A fair bit of our test code was java-without- semicolons as we learnt about Scala...
  • 40. 2009 2010 2011 Jan A fair bit of our test code was java-without- semicolons as we learnt about Scala...
  • 41. 2009 2010 2011 Feb ... despite that we loved it so much that after a month we decided to convert the whole app to Scala java + guice + guice servlets + apache solr
  • 42. 2009 2010 2011 Feb ... 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
  • 43. 2009 2010 2011 May Live!
  • 44. 2009 2010 2011 Jul Switched from maven to simple-build-tool Mainly for incremental compilation
  • 45. 2009 2010 2011 Jul scala + guice + guice servlets + apache solr
  • 46. 2009 2010 2011 Jul scala + lift + apache solr 5k loc => 3.5k (mostly due to writing better scala)
  • 47. 2009 2010 2011 Today • Scala used by default on all new jvm-based projects • Still do some (externally-hosted) new things in python • Team of 20 ex-java devs all audibly groan when working on java rather than scala
  • 49. The Scala “BUT”? But, isn’t Scala really complex?
  • 50. The Scala “BUT”? This example taken from Cay Horstmann http://weblogs.java.net/blog/cayhorstmann/archive/2011/10/05/javaone-2011- day-3
  • 51. The Four Scala Features That Scare Java Developers...
  • 52. The Four Scala Features That Scare Java Developers... ... can all be explained in one slide each
  • 53. Symbolic method names class Complex(real: Double, imag: Double) { def +(other: Complex) = .... }
  • 54. Infix & Postfix Operations • obj.op(x) can be written obj op x • obj.op can be written obj op
  • 55. Infix & Postfix Operations • obj.op(x) can be written obj op x • obj.op can be written obj op So given: val a = new Complex(1, 3) val b = new Complex(3, 4) Can write: a.+(b) as a+b
  • 56. Higher order functions scala> def apply(f: Int => Int, v: Int) = f(v) apply: (f: Int => Int, v: Int)Int scala> apply(i => i * 2, 7) res1: Int = 14
  • 57. Higher order functions scala> def apply(f: Int => Int, v: Int) = f(v) apply: (f: Int => Int, v: Int)Int scala> apply(i => i * 2, 7) res1: Int = 14 scala> apply(_ * 2, 7) res2: Int = 14
  • 58. Higher order functions (ii) // Java  Integer run(Callable<Integer> fn) throws Exception {   return fn.call();  }  Integer processInt(final Integer i) throws Exception {   return run(new Callable<Integer>() {   public Integer call() throws Exception {   return i + 1;          }      }); }
  • 59. Higher order functions (ii) // Java  Integer run(Callable<Integer> fn) throws Exception {   return fn.call();  }  Integer processInt(final Integer i) throws Exception {   return run(new Callable<Integer>() {   public Integer call() throws Exception {   return i + 1;          }      }); } // Scala def run(f: => Int) = f def processInt(i: Int) = run(i + 1)
  • 60. Implicit Conversion • given an in-scope declaration implicit def conv(a: A): B • “conv” will be called whenever you have an A and need a B • or you call a method on an instance of A that doesn’t exist on A but does on B
  • 62. Writing Good Scala • Express your Intent. Simply.
  • 63. Writing Good Scala • Express your Intent. Simply. • The pram is full of toys. Use only to achieve the above.
  • 64. Demo
  • 65. Summary • Smooth migration path from Java • Take it easy, and don’t fear java-without- semicolons in the early days • You’ll lose if you stay there though! • Incrementally embrace Scala features to increase readability • Expect to keep learning
  • 66. • http://content.guardianapis.com • http://www.guardian.co.uk/open-platform • http://github.com/guardian/open-platform- content-api-scala-client graham.tackley@guardian.co.uk ■ @tackers

Editor's Notes

  1. \n
  2. \n
  3. the guardian web site, started ~ 1996, refreshed to current design/platform ~2006+\n &gt; 50m unique visitors a month. \nwe also print a newspaper\n\n
  4. nb: counts of based on wc of non-test code\nimplemented with assistance of our friends from ThoughtWorks (disclosure: I used to work for them)\n
  5. nb: counts of based on wc of non-test code\nimplemented with assistance of our friends from ThoughtWorks (disclosure: I used to work for them)\n
  6. nb: counts of based on wc of non-test code\nimplemented with assistance of our friends from ThoughtWorks (disclosure: I used to work for them)\n
  7. nb: counts of based on wc of non-test code\nimplemented with assistance of our friends from ThoughtWorks (disclosure: I used to work for them)\n
  8. nb: counts of based on wc of non-test code\nimplemented with assistance of our friends from ThoughtWorks (disclosure: I used to work for them)\n
  9. \n
  10. a week is a long time in politics... two weeks is a very long time on the internet\naccidental problems: property converters, repositories, strategies, platform transaction managers, why isn&amp;#x2019;t this a bean etc etc etc\n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. ... that gives us improved speed for change without binning our runtime platform?\n
  20. erm, that Third Way didn&amp;#x2019;t really work\n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. Doesn&amp;#x2019;t just save typing - soon you start writing code like a dynamic language, with the compiler double-checking\n
  28. \n
  29. \n
  30. \n
  31. excited that as other media orgs look to restrict access to content, we look to open access and engage with the rest of the web\n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. Can understand this - prob becuase using java for years\nEvery language has funky bits\nWorking thru a scala tutorial won&amp;#x2019;t teach you everything about scala!\n\n\n
  50. \n\n
  51. Sometimes need to be a bit careful about precedence (use brackets) and where you put line breaks.\nObvious opportunity to misuse!\n
  52. Sometimes need to be a bit careful about precedence (use brackets) and where you put line breaks.\n
  53. For Java folk, think of this as neat syntax for an anonymous inner class\n
  54. Sorry this is two slides.\n
  55. Often used to &amp;#x201C;pimp&amp;#x201D; libraries\n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n