Skip to main content

I’m Dan Corbin, Principal Consultant at Nimble Approach. I’m a software craftsman with an endless curiosity for learning. With over 15 years experience including working as a full stack developer, I now specialise in back end engineering.

My Scala introduction

I’m an experienced Java developer who over the last few years has become proficient enough in Scala to be useful. In this blog I’ll run through my learning journey, sharing nuggets of wisdom that I’ve picked up along the way.

I’m passionate about enjoying software development, and I do this by trying to keep moving forward in a meaningful way, hopefully always learning and ultimately improving.

This is not really a technical note, more of a list of pointers to help you along, if for whatever reason you find yourself on a similar path. Knowing what you don’t know is the first step towards enlightenment.

In the real world, I’ve used Scala to build complex real time promotion capabilities in the context of high throughput event driven applications. In this context the functional programming style that it facilitates and encourages gave high confidence that monetary computations were rock solid.

What I’ve learnt

  • It’s similar, but different – Whilst Scala is principally a Java virtual machine (JVM) language, and this helps familiarity with libraries and tooling, don’t assume that makes the journey any easier. There’s plenty about it that’s very different, and sometimes the similar but different enough details will be confusing rather than helpful.
  • Practice practice practice – You can learn Scala by immersing yourself in a complex real-world codebase. But it is probably not the best way to learn. There’s enough complexity in the language itself that this is likely to be overwhelming. If you get a chance, practice the basics in an isolated part of the code where you’re free to use as few or as many of the language features as appropriate. End-to-end, or performance testing is a helpful place to get started.
Scala Code Example
  • Don’t be impatient, but do get an overview. It can be helpful to read a book such as Scala for the Impatient by Cay Horstmann, and I do recommend it. But, you can’t only read the book. You will need to work through the exercises at the end of each chapter or those such as in the std lib section of scala-exercises.org. It is tempting to think that because you’ve been solving much more complicated problems in Java maybe, and that you get the idea, that’s enough. It’s not; your mental muscle memory will work against you.
  • Don’t use it just because you can – Some developers like to use Scala to demonstrate how clever they are. Undoubtedly you will find code that is really clever, and some of it needs to be to solve the inherent complexity of the problem at hand. It will probably help your wider understanding to work though how to implement the Fibonacci sequence using tail recursion. But is it necessary in your first steps along this new path? You probably have bigger fish to fry!
  • Ease yourself in – As alluded to above, Scala is often used in the context of functional programming. This may be one of your motivations for wanting to learn it. I’m in this group. But functional programming is a whole rich deep subject on its own, so be kind to yourself and ease yourself in gently with something like Functional Programming Simplified by Alvin Alexander. Once you’re beyond the basics, Functional Programming in Scala by Chiusano and Bjarnason takes both subjects to another level. You need to learn to walk before you can run.
  • Scala 2 and Scala 3 are different enough from one another to cause confusion to a beginner. If you are lucky enough to be able to choose, go with Scala 3 to avoid another round of mental muscle retraining.
  • Take this course – I enjoyed the Effective Programming in Scala Coursera course by Julian Richard-Foy that I wished I’d completed much sooner in my studies.
  • It’s a new way of thinking – To start with you might find yourself writing Java-Scala, that is taking a problem in Java, working out how you’d implement a solution in Java, and then translating that line by line into Scala. This will work, but it misses the point really. Scala will most likely give you a new way of thinking about solving this problem.

Moments of clarity

In the next section, I’ve recalled a few lower level notes that came to mind as personal moments of clarity when something clicked.

  • Any operator ending with a colon is right associative. It is a thing of beauty that operators are implemented as methods. But if you miss this detail or rather the deeper implication of it in relation to list processing for example, it will really mess with your mental model.
  • Lean on your IDE as you get going by enabling type hints, or removing syntactic sugar. This will help you make sense of what is really going on under the covers, and get to grips with the many and varied language constructs.
  • Almost all expressions in Scala return a value (even the ones that don’t obviously do so such as println). Yet somewhat ironically, there is no return statement, each function returns the value of the last expression. Again this is straightforward enough but your Java “if else” habit will hinder rather than help.
  • Implicits in Scala 2 will certainly confuse you, especially if they have been misused, and will lead to much head scratching as to how on earth the code you are looking at can possibly work. Your IDE can help you, but the fact that they were significantly reworked in Scala 3 suggests to me that everyone got caught by them at some point or another. Just because you can, it doesn’t mean you should.
  • In Scala a function is a thing (noun) that can be assigned and passed around directly, rather than a behaviour of a thing (verb) i.e. a method on a Java class that is itself referenced or passed. This is simpler really, but different enough from Java that you will find yourself resisting it. Not only can higher order functions take functions as parameters, they can be returned as values.
  • Make a big effort to get your head around complex function signatures and other expressions especially when the syntax starts getting reduced because of conveniences (sugar).
  • Finally, don’t worry when you do see syntax and concepts that you really just can’t get. def freeMonad[F[_]]: Monad [({type f[a] = Free[F,a]}) #f]
  • This will be highly meaningful to functional programming wizards, but I make no apology for finding such voodoo unintuitive, and sleep easily knowing that I’m both fascinated and confounded by some of the more advanced functional Scala you can bump into. It’s all part of the fun!

Summary

Hopefully you’ve picked up something of value from reading this far. Even if it’s simply a sense of not being the only one to find learning tough sometimes.

One of the main things I value when working on a codebase is that it is understandable, and in this regard Scala has both good and bad characteristics. Scala facilitates writing better code. But also it gives more potential for incomprehensible code.

It is likely that you will swap back and forth between Java and Scala projects going forwards, and this is a good thing, as you can use the learnings from each to compliment the other.

I’m most likely a better engineer now than I was before I started my Scala adventure, but irrespective I’ve enjoyed the learning process.

Finally, I think it’s important to recognise that one of your most valuable resources is having a knowledgeable mentor.

In this regard I had, and continue to have the support of colleagues at Nimble Approach who’ve been up that same learning curve, understand the pain points and continue to encourage out a genuine passion for Scala itself, and a dedication to the never ending learning journey that is software development.


Blog author Dan Corbin

About the Author

Dan Corbin, Principal Consultant at Nimble Approach. Software craftsman with an endless curiosity for learning.

I’m a software consultant with over 15 years of experience. Having previously worked as a full stack developer I now specialise in back end engineering focussed on Java and Scala, and the accompanying tech stacks.

I’ve worked in a wide variety of industry sectors including telecoms, FX trading, banking, e-commerce, logistics, gaming, and most recently ed-tech. I have an extra-curricular interest in AI, and am currently studying Neural Networks and Deep Learning.