BT

InfoQ Homepage Presentations How We (Mostly) Moved from Java to Scala

How We (Mostly) Moved from Java to Scala

Bookmarks

Bio

Graham Tackley is the Web Platform Team Lead for guardian.co.uk and a Pragmatic Scala Adopter. He and his team make sure the website can scale and evolve the platform to enable reader engagement in new and innovative ways. Recently, most of his time has been occupied with the Open Platform Content API which provides access to all of the Guardian's current and historical web content.

About the conference

GOTO Aarhus is the enterprise software development conference designed for team leads, architects, and project management and is organized by developers, for developers. As software developers and architects ourselves, we wanted to craft the ultimate conference. The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community, staged in an intimate environment needed to support as much learning and networking as possible.http://gotocon.com/

Recorded at:

Mar 27, 2012

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Slides link

    by Anderson Aroeira Araujo /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    The slides link refers to another presentation... Spring MVC

  • Re: Slides link

    by Yim Carfield /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    right... when will this fixed?

  • Scala backwards compatibility?

    by Chris Kelly /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Did you have any problems with compatibility between Scala versions? One of the bugbears is that sometimes when you upgrade to a newer version of Scala, some behaviour is inevitably broken.

    What strategies if any did you use to mitigate this?

  • Are singletons still evil in Scala?

    by Chris Kelly /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Noticed at the end you mentioned the use of singletons. In a non DI-world, singletons are considered bad practice as you cannot swap out the implementation for say testing purposes.

    Are singletons still evil in Scala?

    :)

  • Re: Slides link

    by razvan baciu /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Thanks for pointing this out. It has been fixed.

  • Do you still have Python/Django?

    by Chris Matts /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Graham

    Did you replace the Python/Django app or do you now need to support java and scala and a legacy python/django app?

    Chris

  • Bad example

    by arnaud m /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    The Java example:
    ArrayList<String> myList = new ArrayList<String>();
    is not very good.

    It should be:
    List<String> myList = new ArrayList<>();
    which is not very far from the Scala version:
    val myList = new ArrayList[String]

    Even it's a bit more verbose, the advantage is that it clearly separates the implementation choice (ArrayList) from the abstract API (List) required for the rest of the code.

    <></string></string></string>

  • Re: Bad example

    by Rhys Parsons /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    But mostly it doesn't matter that your variable type is List<String> or ArrayList<String> because you're only ever likely to be calling methods defined in the List interface. Where it matters, in Scala you can still define it thus:

    val list: List[String] = new ArrayList[String]

    OR

    val list = new ArrayList[String].asInstanceOf[List[String]]

    You're wrong that your Java version and the Scala version are similar in this respect: in the Java version you *always* have to specify the type on the left and right. Your example is being kind to Java. Consider this:

    GenericHeavyLiftingWidget<VeryHeavyObject> hLiftingWidget = new GenericHeavyLiftingWidget<>();
    GenericLighweightLiftingWidget<VeryHeavyObject> lLiftingWidget = new GenericLighweightLiftingWidget<>();
    InMyHumbleNotSoHonestOpinion op = new InMyHumbleNotSoHonestOpinion(new RandomOpinion());

    compared to:

    val hLiftingWidget = GenericHeavyLiftingWidget[VeryHeavyObject]()
    val lLiftingWidget = GenericLighweightLiftingWidget[VeryHeavyObject]()
    val op = InMyHumbleNotSoHonestOpinion(RandomOpinion())

    Note that here I've made use of companion objects which can be a really simple way to implement a factory pattern (and mean that you don't have to use the 'new' operator).

    <></veryheavyobject><></veryheavyobject></string></string>

  • Re: Bad example

    by arnaud m /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    My comment was just about one specific example in the presentation.

    As you say:
    List<String> myList = new ArrayList<>(); // not: ArrayList<String> myList = new ArrayList<String>();
    seems to be semantically equivalent to
    val list: List[String] = new ArrayList[String]
    ... in _this_ case, the Scala code is longer.

    In your example
    val hLiftingWidget = GenericHeavyLiftingWidget[VeryHeavyObject]()
    Yes, of course, if you want the left (abstract) and right (implementation) types to be the same, 'val' is more compact.
    But it allows to write implementation-specific code easier (e.g. a method only in ArrayList, not in List) which is probably not always a good thing. When you read List<String> in a variable declaration, you know that the following code is not dependent on ArrayList or on another specific implementation. (It's not just "free" verbosity in this case.)


    When comparing Scala to Java, just compare it to correct Java code.
    I think Scala is rich enough (SAM vs first-class functions, covariant generics,...) so that you don't have to use a trick to amplify the difference.
    (I see that several times in various Java/Scala comparisons.)
    </string></string></string><></string>

  • Re: Scala backwards compatibility?

    by Graham Tackley /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hi Chris,

    It's never been a real problem for us. We wait until all the libraries we use are published for a new scala version and then we upgrade. And it's just worked - there's never been anything other than trivial changes we've had to make to any of our codebases to compile with new scala versions.

    For shared libraries, we cross compile against all the scala versions we have in use, using sbt.

    Personally I prefer this to a backwards-compatibility-at-all-costs, which ends up with things like HttpServletRequest.getHeaders returning an Enumeration (effectively deprecated in java 1.2).

  • Re: Do you still have Python/Django?

    by Graham Tackley /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    The Python/Django app is still running, though we are in the process of replacing it with Scala.

  • Re: Do you still have Python/Django?

    by virtual eyes /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Uh oh, Twitter ditches Ruby/Rails for Scala; Guardian ditches Python/Django for Scala

    A paradigm shift in the works methinks.

    Love me some Scala, yes indeed ;-)

  • What about Grails?

    by Daniel Paniagua /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Did you consider Grails during your evaluation? Conclusions?

  • Demo Video

    by Bad Ninja /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    20 minutes of this video is unwatchable during the demo part. Fail.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.