Your SlideShare is downloading. ×
0
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
LSUG: How we (mostly) moved from Java to Scala
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

4,550

Published on

Presentation from talk done at the London Scala User Group on Wednesday 12th Jan 2011. …

Presentation from talk done at the London Scala User Group on Wednesday 12th Jan 2011.

http://skillsmatter.com/podcast/java-jee/how-we-mostly-moved-from-java-to-scala

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

No Downloads
Views
Total Views
4,550
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
88
Comments
0
Likes
9
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
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
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript

    • 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
    • 8. January 2010
    • 9. January 2010• A fair bit of our test code was java- without-semicolons as we learnt about Scala...
    • 10. January 2010
    • 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 2010Still 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 & varList<String> myList = new ArrayList<String>(); =>import java.util.ArrayListval 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 OneSensible class constructors +1No getters & settersval and var, implict variable typing +4No filename restrictionsNo need for semicolons +1Same tools, lib, depoyment, runtime characteristics as java +1Less { }object keyworddecent collections library“”” string notationlist.filter(_.test).map(_.transformation) +1case classes for value object +2default parametersregexes: .r & unapply +1it’s fun!val => encourages immutubilitytraits +2match statementslibrary DSLs such as lift-jsoneasy maps and listsREPL +1write the java you know then refinemap, filter etcFar more expressive codeFunctions 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. Optionor 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 TODAYWe now think of Options as lists with zero or one entries
    • 27. 2. powerful collections libraryit took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
    • 28. 2. powerful collections libraryit 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 nullsWe used implicit conversions to hide the Java yuk demo: RichSolrDocument
    • 31. 5. pattern matching demo: UserTier
    • 32. After a couple of monthsUsing Option properlyFunctional programming - i.e. without side effects +1Powerful collections librarytraits as mixins +2json & xml parsing & generationimplicit conversions to enhance existing classes +2regexesapply and unapply methodsinfix statementslearning not to overcomplicatethinking functionallyDSLsActorsRename imported classesExtractors & pattern matching +1Passing closures allCompanion object patterncurrying functionsdefault parameters and case class copy methodsparser combinators +1implicits and traits instead of dependency injectionpartial functionsnull is not an option
    • 33. 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
    • 34. • 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

    ×