👋 Hello! If you’re already sold on Scala, feel free to skip to the getting started section 👋


“Why do you use Scala?”

…is a question that came up more and more often as people are gaining more awareness of the programming language. I normally spoke of my own personal experience, but for the most part, Scala is my go-to language because it offers me flexibility in how I can express my thoughts into code. ‘Code is Prose’ is certainly very apt here (more on this later).


“But there are other, more elegant programming languages out there…”

Scala is not perfect, but it is pragmatic. I am enjoying the expressiveness and flexibility it offers while being able to tap into the rich and diverse JVM ecosystem. It does strike a nice balance between: usability, community size, and employment opportunity 😜


“Java has lambdas!”

But Scala is much, much more than lambdas. Interesting things can happen when you have a language that combines Object-Oriented (OO) with Functional Programming (FP) approach, complemented with a rich type system. Pattern matching, Algrebraic Data Types (ADT), and monadic comprehensions are some very useful constructs that do not exists ‘natively’ in Java.

To give a very quick example, observe the following Scala code:

sealed trait Drink
object Drink {
  final case object Coffee extends Drink
  final case object Tea    extends Drink
  final case object Soda   extends Drink
}

def whichBrand(d: Drink): String = {
  import Drink._
  d match {
    case Coffee => "Starbucks"
    case Tea    => "Dilmah"
    //case Soda   => "Coca Cola"
  }
}

Note that match against Soda has been commented out. When compiling the above as-is, the compiler will throw a warning:

match may not be exhaustive. It would fail on the following input: Soda

A combination of pattern matching and ADT provides exhaustivity checks during compile-time. Of course, this is only one of many useful features available in Scala.


“I heard Scala code is impossible to read!”

It depends, I think there are some contributing factors here:

  • Scala is highly contextual
    It will be challenging for Scala beginners to identify these contexts (e.g. the use of symbols, implicits, syntax styles), but once learnt it’s quite amazing how a concise piece of code can carry so much information. I highly recommend going through Manabu Nakamura’s slides on ‘Readable Scala’ presented at Scala Matsuri 2017.

  • Scala code moulds according to the engineering culture
    Because Scala is flexible, from syntax styles, choice of libraries, to architecture, it’s not uncommon for new developers putting in non-trivial effort to match and adapt to the existing team’s culture. Regardless, have mentoring and / or pair programming in place.

  • Scala evolves relatively quickly
    Scala releases are highly iterative and changes faster compared to languages such as Java. Syntax styles, design patterns, and libraries that were considered best practices three years ago might already be outdated now. Developers (new and experienced alike) need to pay special attention when using Scala code found in blog posts and StackOverflow responses. Check the publish date 👌


“Why should I learn Scala?”

So let me reiterate again the why in hope of convincing you to learn Scala:


Scala helps you write expressive and maintainable code without sacrificing usability


Consider that most of the time we (developers) spent reading code as part of an effort to write new code. Despite the Scala ‘tax’ for new developers, code which is moulded to solve the particular problem at hand is more readable and leads to better long-term maintainability. You will also be able to leverage familiar tools when writing code and after deploying it to production: access to mature and proven Java libraries, toolkits (e.g. profiler), and IDEs such as Eclipse and IntelliJ IDEA.

As an aside: I didn’t seek out to learn Scala, rather it began as an exercise to keep a hobby project up-to-date (Play Framework 1.2 to 2.x migration); though I am glad it has allowed me to learn FP concepts, actor model, reactive systems, and many others. Perhaps this is a story for another blog post some other day.


“But where do I start?”

…you ask? Being a general purpose language, Scala materials out there can cover anything from concurrent programming to recommendation systems. I hope to address various different categories separately in the future, but here are some good resources to get you on your journey:

Last but not least, check out Awesome Scala for a community-curated list of awesome Scala libraries.




“I just want to give it a quick spin…”

Skip a bunch of installation steps and just get right to coding! Both websites are free, but requires you to link your GitHub account to unlock the entire functionalities.

  1. Head over to Scala Exercises and try out the STD LIB exercises (ignore the others for now).
  2. Play around with Scastie, a web-based interactive Scala editor.


“How to run it on my machine?”

Well, it doesn’t surprise me if you think Scala is awesome 😁 Depending on what you want to do next:

  • Install Java SDK 1.8 (I recommend Azul Zulu), to run your application.
  • For interactive console / REPL only:
    • Install Scala binaries.
  • To start writing Scala applications:
    • Install SBT, the de-facto build tool for Scala projects, and / or
    • Install a text editor or IDE with Scala support, I highly recommend IntelliJ IDEA for a no-fuss setup (community edition is free).

Note: You can start writing Scala applications just by downloading Java SDK and IntelliJ IDEA. IDEA can take care various mundane tasks such as downloading SBT and Scala binaries as part of its workflow when creating new Scala projects.


“I am a Java developer”

I’m glad to hear that, it means you are already familiar with the Java ecosystem and should have a head-start in Scala programming. However, besides learning the language, I would also recommend you to spend a bit of time to learn SBT (Scala Build Tool). While you can use Maven or Gradle for Scala projects, SBT will be a far more pleasant experience:


“I want to learn more Scala”

That’s great! I can point you to a few resources to help you improve your Scala knowledge:


“I need to level up in Scala!”

Once you have an understanding of basic Scala concepts, now it’s the time to explore Actors and the functional side of Scala:


“Where can I find other Scala developers?”

Learning is much better together!

  • Scala on Gitter is the official Scala channel on Gitter messaging platform.
  • #scala on IRC for various Scala-related chat on IRC.
  • Scala Space shows various Scala-related groups near you, such as Meetup groups.




Referenced blogs, docs, and presentations (A-Z):




Updates:

[2017-08-03] — Added community resources and incorporated feedback from fellow developers