Scala Saturday: Make 2017 The Year You Learn Scala

A weekly series of articles about Scala and functional programming

Mark Canlas
3 min readJan 16, 2017

Welcome, 2017! It’s a new year and an opportunity for the new you. See ya 2016, with your unsafe programming practices and mutable data structures. So long, unvalidated input data and unchecked exceptions! Together, we’re going to explore the wide world of Scala and functional programming.

Some concepts in functional programming can seem intimidating, but they don’t have to be. Cast your fears aside and make this the year you slay the functional dragon. We’re going to tackle questions like…

  • Dynamic or static typing?
  • What is immutability?
  • What is a monad and why does it keep coming up?
  • How do you pronounce Scala? (it’s “SKAH-lah”)

Who, me?

Yes, you! This article series is for software engineers looking to improve their craft through the lens of functional programming. Maybe you’re a backend engineer implementing REST endpoints for a user-facing product. Maybe you’ve heard of functional programming but still aren’t sure what it is. Maybe you’ve already tried some functional patterns but want to learn more. Or maybe you just like reading blog articles with your morning coffee.

Let’s assume that you are already familiar with object-oriented ideas and build from there, like variables, classes, class instances, methods, and inheritance. Let’s also assume you value ideas like expressive power, brevity, testability, reliability, and correctness. These are all the things you will need to learn about functional programming with Scala.

Why Scala?

Scala allows object-oriented programmers to get acquainted with functional programming in small doses.

If you frequent /r/programming or Hacker News, you’ve probably seen Scala mentioned. It’s is a multi-paradigm programming language, both object-oriented and functional at the same time. Scala uniquely affords the opportunity for programmers familiar with object-oriented programming to get acquainted with functional programming in small doses.

I often describe learning Scala as a continuous journey. You can be productive with Scala right from day one, writing in a style similar to Java or any object-oriented language. But as you learn about more constructs and idioms, you will see that the preferred style in Scala is often more functional than not. Reading your old Scala code can be a bit of a sobering experience after you’ve become more fluent with functional idioms. “Why would anyone write that?” your future self might exclaim.

Consider the following block of code. It could be similar to the way you or your coworkers write code today. (By the way, the val/var distinction is intentional.)

And here’s the same code in more idiomatic Scala.

This alternative is much more pleasant to read and easier to work with.

Big data

There it is. I spiked this article with another buzzword.

With its JVM infrastructure and penchant for immutability, Scala is making big strides in industries like ad-tech and finance where the parallel processing of data needs to happen reliably and at scale (hence the name). Scala is a popular option for data pipelines with real-time streams or offline batch processing as well as in businesses that have already committed much of their infrastructure to the JVM as traditional Java shops.

I guarantee that by the year’s end, you will have gone from monadic zero to functional hero. Happy hacking and see you next week for another Scala Saturday!

--

--