Marcus Ljungblad is going to give an amazing Scaladays talk about the process of learning Scala, and he put out a call to his fellow hackerschoolers for suggestions. I was glad to chip in, because I enjoy the opportunity to blurt out opinions without the obligation to structure them eloquently, and talking in front of people is scary, so it's awesome to have somebody else do it. Still, I kind of like my suggestions, and with Marcus' permission, I'm going to offer them here. This isn't a getting started guide, and it certainly isn't a tutorial. I'm assuming you have those, but that they do not sufficiently stress the following:

  1. As early as possible, learn how to use sbt. Any OSS project you clone will have a build.sbt, and anything you share yourself will be expected to have one too.

  2. From a build.sbt, it is easy to create configuration files for Eclipse (using sbteclipse), IntelliJ (the latest version allows you to import a built.sbt directly), or emacs/ensime (which you shouldn't use unless you're a nut 1) It is not easy to go the other way. Whenever you change dependencies or versions, make the changes in your build.sbt first regenerate the IDE configs there, and bounce the IDE.

    Otherwise, it will be hell to get back to a state that can be shared with the world.

  3. Learn what persistent data structures are, and understand that Scala's immutable collections are implementations of them. Otherwise, you'll find yourself wondering - as I did, nearly causing me to ditch the entire language in disgust - why a person would ever want an immutable hash map. Clojure partisans justifiably make a bit deal of their persistent data structures and how they allow you to code efficiently without mutable state. Scala largely uses the same algorithms but for some reason doesn't trumpet the fact. If you keep it in mind, you'll be far less hesitant to dive into truly functional code.

  4. You'll learn about the REPL soon enough. What you probably won't learn soon is that

    scala -Xprint:parser -e "for (i <- 1 to 5; j <- 1 to 4) yield i*j // or whatever"```

    will show you how Scala desugars your code, revealing what's really going on in some sophisticated code snippet you're trying to grok. In a similar vein scala -Xshow-phases lists all the other things you can -Xprint.

  5. The preceding example, in particular, demonstrates something else to get under your belt as soon as possible. for comprehensions are not just funny for loops. They are handy sugar for map and flatMap, and they get used for much more than just looping. Delaying this realization will make the language seem easier, but in the long run it'll cost you. You need to know about this maping business, because it shows up everywhere, for example in the Option that gets returned when you do something innocuous like a hash lookup.

  6. Which brings us to pattern matching, destructuring and case classes. Things like

    whatever match {
          case Some(Foo(x)) => doSomethingWith(x)
          case None => doSomethingElse()

    will show up over and over again, and it's tempting to think of them as a cool feature that maybe you'll use someday. Actually, you'll use it immediately and again and again.

  7. Stay away from DSLs as long as possible, which basically means that if you come across funny punctuation symbols used in a weird way, you should wait until you've implemented something like that yourself. Akka is amazing, but using it too early makes the language seem magical and suppresses your deeper understanding of it.

  8. Bookmark this FAQ on the "standard" weird symbols, and count on referring to the section on underscores relatively often.

Bonne chance.

  1. Like me. 


comments powered by Disqus