Learning Scala

Some questions for people who are learning / have learned Scala: What languages did you know beforehand, and how easy did you find learning Scala in comparison to these? Are there any languages which you found knowing particularly helpful when picking up Scala?

An explanation follows:

Scala seems to be a relatively hard language to learn for some people, not so much for others. Part of this is its complexity – it really does have a lot of little features – but I’m wondering if more of it might be its approach. It’s a language with two major inspirations – object orientation (in the peculiar flavour of it Java practices) and statically typed functional programming, and I’m not sure how easy it is to understand the language unless you understand where it’s coming from in this regard.

In particular one thing we’ve observed in #scala from people learning the language is that if you know both Java and Haskell (I presume an ML would work as well?), learning Scala becomes significantly easier. I had almost no trouble picking it up, but I know both. Ricky Clarkson seems to be in a similar boat in terms of Haskell + Java having helped. I presume others are too. On the other hand, people with Java background but not much FP seem to have more trouble and people coming from a predominantly ruby or python background have a harder time yet. (I don’t know what happens to people coming from a Haskell with no Java background. I’d expect a similar degree of confusion to the Java with no Haskell background).

Some of this is probably in terms of material – a lot of Scala tutorials, etc. out there seem to assume you already know Java. This is probably largely accurate but seems like a mistake in the long-term to me. On the other hand, I’d be really uncomfortable teaching Scala as a first language, so what languages *should* they be learning to prepare the way? Anyone tried learning it on the basis of, say, Ruby + OCaml?

So, what do we want people’s path into Scala to be? Should we suggest they learn Java first if they don’t want a bit of a rough start, or is there a better way?

This entry was posted in programming and tagged , , , on by .

5 thoughts on “Learning Scala

  1. Tom Davies

    I know Java (well) and Haskell (not so well).

    My attempts so far to learn Scala haven’t been too serious. The obstacles I’ve found so far are to do with the multi-paradigm nature of the language. When you learn Haskell there are really just a few concepts (functions, algebraic types and type classes) — everything is built out of that. Scala seems much larger, and it is hard to know where to start.

    I began working on the Project Euler problems in Scala, after reading the first few Chapters of ‘Programming in Scala’, but soon went back to using Open Quark because the problems suited a functional style so well. Of course I later discovered that Scala can do all that very well, but the book seems to begin by teaching idioms which you would not actually ever want to use, given the other features which Scala has!

    When the physical copy of the book arrives I will sit down again and learn the whole language, but that’s my experience so far.

  2. C.J. K

    I came to Scala knowing Java very well and Ruby reasonably well. I’d fallen in love with Ruby’s blocks and was looking for something similar in a statically-typed language compatible with Java. I had no experience of functional programming at all.

    I found Scala fairly easy to pick up and the functional elements of it led me to dabble in Haskell and Erlang. After that the functional parts of Scala made a lot more sense.

  3. Matth

    I work mainly with Ruby, but have also studied and played with functional programming a fair bit (Haskell mainly, but also OCaml and Scheme – can’t say I’ve used them for anything that important, but found them very interesting).

    I’ve played with C and C++ in the past and this probably helped too – but have never really touched Java in anger.

    I’d say you’re fine if you’re familiar with:

    – A functional programming language
    – An class-based object oriented language
    – A statically typed language (which is ideally one or both of the above)

  4. James Iry

    As a guy who learned both Scheme and Haskell after Java but before Scala I can certainly agree that having a background in both OO and FP helps with Scala. But ya know, I have hope that even for people who basically only know single dispatch OO Scala will bring benefits.

    Back in the day when C++ was becoming popular most coders didn’t know anything beyond procedural code. For a long time there was a lot of C++ code that was basically C with Strings plus some slightly more sane typing and scoping rules. Now, that was pretty bad in a way. It ignored all the power that was available in C++. But it was a gain, too. A lot of code deals with strings and C’s naked char pointers are very hard to get right without shooting yourself in the ass.

    So perhaps all the hybrid languages like Scala and F# (and to some extent Ruby, Python, Javascript and C# 3) are going to be treated like “Java with map and foreach.” Not a huge gain, but it’s something. A lot of code deals with transformations and iterations over collections and, while loops aren’t quite as hard to get right a char pointers, there’s still something to be said about not thinking about loop invariants and all that crap.

    At the same time there might be value in teaching FP to OOists by pulling back the covers of Scala and showing that function values are just objects with one method. It doesn’t quite convey the power of closure values nor the clear reasoning available with immutable data, but again, it’s a start.

  5. Chris Hagan

    C#.

    I’m not saying they’re identical, or making a value judgement… But I moved my project over to Scala because I wanted the java libraries behind me, and I found that the inline lambda stuff C# adds to Java made it a very nice bridge.

Comments are closed.