Java to scala

5,849 views

Published on

Graham Tackley discusses Scala adoption at the Guardian

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,849
On SlideShare
0
From Embeds
0
Number of Embeds
4,749
Actions
Shares
0
Downloads
28
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Demo\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Java to scala

    1. 1. (mostly)How we moved from ^ Java to Scala Graham Tackley guardian.co.uk
    2. 2. History• Java shop since 2006• guardian.co.uk: java + spring + velocity + hibernate + oracle• ~100k lines production java code (and ~35k xml...)
    3. 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. 4. Content API(demo of http://content.guardianapis.com)
    5. 5. November 2009• Started new Content API implementation• java + guice + guice servlets + apache solr
    6. 6. November 2009• A few people had played with scala• No production scala code
    7. 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
    8. 8. January 2010
    9. 9. January 2010• A fair bit of our test code was java- without-semicolons as we learnt about Scala...
    10. 10. January 2010
    11. 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. 12. Our top 5 things we loved about scala on day one
    13. 13. 1. Sensible Class Constructors =>
    14. 14. 1. Sensible Class Constructors
    15. 15. 2. Type inference / val & varArrayList<String> myList = new ArrayList<String>(); =>val myList = new ArrayList[String]
    16. 16. 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
    17. 17. 4. REPL (console)• run “scala” for a scala shell• awesome for experimentation
    18. 18. 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
    19. 19. 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.
    20. 20. July 2010• Switched from maven to simple-build-tool• Mainly for incremental compilation• ~ test-quick and ~ prepare-webapp also invaluable
    21. 21. Writing codeone year on
    22. 22. some early code...it took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
    23. 23. ... ended up asit took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
    24. 24. 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
    25. 25. • 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

    ×