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 April 2010:
http://content.guardianapis.com
4. December 2009
• Started new Content API implementation
• java + guice + guice servlets + apache solr
5. December 2009
• A few people had played with scala
• No production scala code
6. 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
10. 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
14. July 2010
• Switched from maven to simple-build-tool
• Mainly for incremental compilation
• ~ test-quick and ~ prepare-webapp also
invaluable
15. Feb-Oct 2010
• Much learning within the team as to how to
write concise, readable Scala code
16. Option
or How we learned to stop worrying and love the Option
We’d read “don’t use nulls, use Option instead”
DAY ONE
s/x == null/x.isDefined
DAY THREE
x match {
case None => ...
case Some(value) => ...
}
17. 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
18. map & flatMap
it took us a while to realise that most of the loops we
wrote in Java were actually “map” or “flatMap”
19. Java Libraries
Content API extensively uses Solr/J,
which is good but returns loads of nulls
And don’t get me started on HttpServletRequest...
We used implicit conversions to hide the Java yuk
20.
21. 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