Java to scala
Upcoming SlideShare
Loading in...5
×
 

Java to scala

on

  • 5,362 views

How we (partly) moved from Java to Scala. Talk at Scala Lift Off 7 Oct 2010

How we (partly) moved from Java to Scala. Talk at Scala Lift Off 7 Oct 2010

Statistics

Views

Total Views
5,362
Views on SlideShare
5,345
Embed Views
17

Actions

Likes
8
Downloads
84
Comments
0

2 Embeds 17

http://www.linkedin.com 15
http://www.linkedin-ei2.com 2

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Java to scala Java to scala Presentation Transcript

  • (partly) 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 April 2010: http://content.guardianapis.com
  • December 2009 • Started new Content API implementation • java + guice + guice servlets + apache solr
  • December 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
  • 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
  • July 2010 • Switched from maven to simple-build-tool • Mainly for incremental compilation • ~ test-quick and ~ prepare-webapp also invaluable
  • Feb-Oct 2010 • Much learning within the team as to how to write concise, readable Scala code
  • 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) => ... }
  • 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
  • map & flatMap it took us a while to realise that most of the loops we wrote in Java were actually “map” or “flatMap”
  • 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
  • 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 • http://blog.tackley.net graham.tackley@guardian.co.uk