2022 Year of Scala Recap

scala
learning
yearly-review
Recaps, Learnings and Reflections
Author
Published

December 31, 2022

My Year of Scala

In 2022, I chose the Scala programming language as my learning theme. This meant that I would use Scala in projects big and small, with a focus on understanding how I could incorporate Scala into my toolset. I shared my motivations in greater detail in an earlier blogpost 2022: My Year in Scala.

As we end 2022, here’s my recap and reflections on how I got to understand this programming language better and what I would recommend if you are interested to do the same.

Projects I completed with Scala

Learning by doing has always been the most effective way to learn new things. One of the advantages to focusing on a single learning goal for an entire year is that I could pepper in both small and large Scala projects. This helped me to protect against my enthusiasm to use Scala for everything, and hopefully I avoided the classic β€œif all you have is a hammer, everything looks like a nail” trap. Here are some of my favourite projects that I completed with Scala:

1. Built a scala application for Work

My impetus to learn Scala was primarily because I had to use it at work, so I am very proud of the fact that I got sufficiently up to speed with Scala within the year to actually build a Scala application that that adds value to myself and my team 😊!

I won’t dive into specifics on this public platform to respect sensitive work projects. But just to get a sense, this application interacts with an enterprise-grade Spark cluster and handles an enterprise-grade volume of data. Most importantly, this application fills in a gap in our existing tooling and delivers real value for its users. The choice to use Scala for this application was perfect because there was plenty of interaction with Spark and that it fits in well with our existing codebase.

Did I mention β€œenterprise-grade” enough? πŸ˜†

2. Built a Random Number Generator for School

I took a course on Simulation and Modeling as part of my part-time masters programme this year. Our final project had a variety of questions and I chose to attempt one that required an implementation of one of the many Random Number Generators learnt in class.

I used Scala to build a Tausworthe Generator that required multiple data transformations and bitwise operations. I reflected that Scala’s Type system and ease of data transformation patterns made for such a great fit for this project.

3. Attempted this year’s Advent of Code in Scala

Every year, I get excited for the global coding challenge known as the Advent of Code. In preparation, I worked my way through the Scala solutions for 2021’s AoC and consolidated a few Scala tips in this blog post.

Using Scala for 2022’s challenge was also incredibly fun! The challenge really nailed home that Scala is a high level language well-suited for the general problem solving. In particular, I really enjoyed Scala’s flexibility as it relates to using mutable/immutable data structures. While the immutability is encouraged as a default, no one bats an eyelid if you choose to use mutability on occasion, because frankly some problems in AoC are much easier to grok that way.

What I liked about Scala

After a year of trying to learn not just the syntax of the language but also appreciate its design, my favourite thing about Scala is how ergonomic it makes writing code feel.

Scala reminds me of several specially crafted ergonomic tools that I have come across, such as the Eames chair or the Dvorak keyboard. On first impression, most people find these tools strange and question why anyone would use something so different from the norm. I certainly felt that same way approaching Scala, coming from a primarily Python background. I could not understand why there was such an emphasis on the Type system, the functional patterns seemed foreign to me and I was curious why there was a small niche community that seemed so fervent in their support for this strange language.

I am glad I had an entire year to incorporate Scala into my daily tasks, because I eventually grew to enjoy Scala. Scala has an expressiveness that seeps into how I approach problems, and how I think about solutions. I still find reading scala code idiosyncratic at times but I also get occasional Aha moments where I appreciate the elegance of how a solution is communicated. Similar to the aforementioned designer chair and keyboard layout, once you commit to using these tools, you start to appreciate its intentional design and ergonomic benefits.

While its community and usage is (and probably will always be) niche, I have also found them to be welcoming and patient with new users like me! You can connect with the community primarily on the Scala Discord server or on /r/scala.

I consider myself way too green to give a proper commentary on Scala’s core design so instead let me echo this point from Li Haoyi’s Hacker News thread about Scala. Comparing programming languages is complicated, but from a distance, it truly does feel like many other languages are converging to the features Scala provides today. And, I think this says a lot about how thoughtful and well implemented the Scala language is.

What I disliked about Scala

To keep things balanced, I also want to touch upon things I struggled with this year.

1. Tooling

I did not enjoy the β€œenterprise-grade” Scala build tool sbt. That sbt once represented β€œSimple Build Tool” must surely be someone’s cruel joke. I remember vividly being particularly annoyed that to run a simple Hello World example, many sites wanted you to first grok sbt. I felt that the context switch to understand build tools in general and sbt in particular took my attention away from trying to learn the basics of Scala.

I bounced around to other build tools, such as Mill but felt that outside of a handful of projects, I could not find sufficient examples particularly of simpler projects using Mill to help me better understand the tool.

My saving grace came later in the year when scala-cli picked up development steam. scala-cli is not a full fledged build tool capable of replacing sbt, but it was exactly the tool a beginner like me was looking for. A simple tool that allows the user to run Scala applications and occasionally handle simple packaging.

I’m so glad to hear scala-cli might go on to be the default way we execute scala code in the future. I think it would alleviate one of the biggest hurdles beginners have to overcome when first learning Scala.

2. Documentation

I’m probably spoilt by the huge amount of documentation available online for Python and its landscape of libraries. Additionally, it is not just the quantity of documentation and answers for all things Python, it is also the SEO.

I found it so perplexing that simply Googling a Scala library name and method often does not yield the correct documentation page I am looking for as a top result. Even after I located right ScalaDoc page, I found navigating the page difficult and discoverability for new methods poor. I sorely missed having example lines of code showing a method’s usage which is something I have gotten used to from reading documentation sites for pandas or numpy.

Note

As I’m proofreading my post before publishing, I am pleased to have found that the issue with ScalaDoc’s layout is being fixed! See this reddit post for more info!

What I Would Recommend

If you are embarking on your own Scala learning journey, here are my recommendations.

Basics

The best resource I found for learning the basics of the Scala syntax is Scala Exercises, particularly the module introducing the standard library. In there, you will find a dedicated set of explanations and interactive examples for all the key Scala language features.

Another great resource for learning the basics would be the official Tour of Scala.

Practice

As mentioned above, I am a big proponent of learning through practice. So my recommendation is that once you get a good understanding of the basics, you try your hand at completing some classic programming puzzles or tasks. I am very fond of the Advent of Code but feel free to try your hand at other well known resources like Project Euler or Leetcode.

I would recommend to aim to use Scala’s standard data structures to solve these puzzles. These buiding blocks are incredibly robust and powerful and are key to unlocking a lot of the ergonomy I alluded to earlier.

Textbooks

I surveyed a variety of textbooks in the year, and for the most part, all of them were good. If you’re pressed to choose, I found myself coming back again and again to Hands-On Scala. This textbook was my favourite because it had a nice variety of projects that you could incrementally build along whilst learning more about Scala and its ecosystem.

Tooling

For beginners, I advocate for what I consider to be the most frictionless path to get started writing Scala code:

  • Install everything you need to write and run Scala via Coursier
  • Use scala-cli for compiling, running and packaging Scala scripts and applications
  • Use Vscode with the Metals extension as your development environment.

There are many alternatives to these technologies but you can take your time to explore them after you get started.

Conclusion

I had a blast in 2022 working my way through Scala! It has been one of the most interesting and rewarding learning topics I have attempted.

Bonsai Tree/Scala logo – https://lexica.art/prompt/e42e0aba-a2cb-42fe-b952-2abdf8431ef0)

As we move onward to 2023, I have no plans of dropping Scala from my toolset. Scala will remain one of my favourite languages to solve problems with. Honestly, it has pretty much become my daily driver.

That said, I am absolutely itching to find a new topic to sink my teeth into for 2023. Let me know if you have any suggestions for me. Happy learning everyone! πŸ€”πŸ€”πŸ€”

Appendix

─ Session info ───────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.3.2 (2023-10-31)
 os       macOS Sonoma 14.1.2
 system   x86_64, darwin20
 ui       X11
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Asia/Singapore
 date     2024-01-01
 pandoc   3.1.10 @ /usr/local/bin/ (via rmarkdown)
 quarto   1.3.450

─ Packages ───────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 sessioninfo * 1.2.2   2021-12-06 [1] CRAN (R 4.3.0)

 [1] /Users/ddanieltan/Code/ddanieltan.com/renv/library/R-4.3/x86_64-apple-darwin20
 [2] /Users/ddanieltan/Library/Caches/org.R-project.R/R/renv/sandbox/R-4.3/x86_64-apple-darwin20/84ba8b13

──────────────────────────────────────────────────────────────────────────────
If your experiment needs statistics, you ought to have done a better experiment – Ernest Rutherford

Reuse

Citation

BibTeX citation:
@online{tan2022,
  author = {Tan, Daniel},
  title = {2022 {Year} of {Scala} {Recap}},
  date = {2022-12-31},
  url = {https://www.ddanieltan.com/posts/2022scala-recap},
  langid = {en}
}
For attribution, please cite this work as:
Tan, Daniel. 2022. β€œ2022 Year of Scala Recap.” December 31, 2022. https://www.ddanieltan.com/posts/2022scala-recap.