A Scala journey: from Java weariness to ADTs and public speaking
Next in our Scala interview series is a Scala Developer, author, and maintainer of numerous handy OSS libraries.
Here comes another instalment of our Scala interview series! This time, a Scala Developer, author, and the only maintainer of several handy OSS libraries, shares his perspective with us!
How did you first come across Scala, and what was your impression of it?
That was quite some time ago! For nearly 15 years I had worked professionally mostly with Java, I was growing a bit weary of solving the same problems with the same solutions over and over, and I wanted something fresh and demanding.
Since I knew the JVM well, I began exploring languages running on it and came across Scala. As I was browsing some code samples, a friend glanced at my screen and advised me to drop it. In his view, Scala was much too complex for me.
Naturally, I treated that as a personal challenge, threw myself into the language with an enthusiasm I might otherwise have lacked, and ended up falling in love with it.
Describe the moment you thought, “Wow! Scala is great!” Which Scala features and capabilities gave you that feeling?
The first feature that convinced me the language was genuinely fun is one I practically never use or miss – trait linearisation. During my Java years, I kept running into problems I would have liked to solve with multiple inheritance, which, naturally, is impossible there. Trait linearisation enables it by offering a deterministic way of resolving conflicts between inherited members, and I thought it would unlock a whole new world of solutions for me!
Ultimately, though, I have never needed it. Other features, like Scala’s take on type classes, made the problem disappear altogether, so solutions to it stopped mattering.
The feature that really blew me away and has permanently shaped how I write code, in any language, is Algebraic Data Types.
In what way has Scala shaped how you approach programming problems?
Scala changed how I program by showing me the idea of Algebraic Data Types.
Algebraic Data Types are my favourite primary tool for solving problems. The approach is simple: describe the problem using ADTs, write functions that transform them one step at a time, and you’re done. I love that ADTs make data modelling easy and let me see problem-solving as a process of transforming data.
If you were able to add a new feature to Scala, which one would you pick, and how would it help developers?
That’s a hard one. Back when Scala 2 was the cutting edge, the feature I wanted most was GADTs: they were supported in a way, but they fell apart the moment you attempted anything a bit interesting – for instance, try writing a type safe printf and scanf in Scala 2, and the compiler pretty much throws in the towel.
Scala 3 has largely fixed this – perhaps completely by now? When I experimented with Scala 3’s GADTs in the past, I ran into some strange problems, but the maintainers diligently fixed the issues I reported. Full support may very well be available now. If so, I’m not really sure what other features I’d need from Scala. Maybe something similar to Rust’s borrow checker for handling resources and their owners?
Which tools and libraries do you reach for first as a software developer?
These days, I actually do my best to keep dependencies as few as possible. Writing a project without any external library at all counts as a complete win for me.
Naturally, a few libraries end up in my builds again and again: cats, for instance, usually when I suddenly feel the need to sequence or traverse something. Or circe, whenever I have to deal with JSON – which, frankly, happens much too often nowadays.
Recently I’ve been trimming down my toolset. Partly that comes from the frustration of spending more time repairing tools than they save me. Metals, for example, is excellent when it works, but becomes a nightmare when it doesn’t. In the end, I concluded that for what I need, I’m better off without it. These days I mostly rely on SBT for builds, scala-cli for trying out quick ideas, and Emacs for the rest.
What impact has the Scala community had on your programming journey? Any memorable interactions or stories of support?
Nowadays, a big part of my time goes to giving conference talks and helping train less experienced developers. This has totally changed the way I think about programming and solving problems. My goal now is solutions I can explain to newcomers or, better yet, ones a newcomer can look at and say, “of course, what other way would there be to solve it?”
It’s all the Scala community’s fault! Several years ago, I went to Scala.IO and had a great time. A member of the organizing team proposed that I prepare a talk for the following edition. Writing it was something of a battle and took me nearly a year. Still, I finished it, submitted it, got accepted, and that’s how I found out I love public speaking.
My very first public talk was quite an intense experience. I spoke in French about the problems and design mistakes I saw in Scala, together with ways to work around them. While setting up in the room, I counted roughly 20 people, yet in my head it felt like 2,000. To make things even more stressful, Martin Odersky, the creator of Scala, was sitting in the front row in the right corner. At first I was terrified, but I calmed myself with the thought that the talk was in French, a language he probably didn’t know, so I’d be fine.
A few minutes into the talk, though, Martin put up his hand and politely noted that I had misunderstood a feature. That’s how I learned he spoke French, which made everything even more nerve-racking. The rest of the talk went on in the same way, with me being gently corrected as I fought my way to the end. Explaining what a type class is turned out to be particularly hard. Martin, politely once more, asked me to begin again, saying that while I did understand it, my explanation was confusing.
In spite of the nightmares I had before taking the stage, the story ends happily. Martin encouraged me to submit the talk to ScalaDays, and I’ve been speaking at events ever since.
Were there any funny or embarrassing moments while you were learning Scala?
Oh, embarrassing moments, there are plenty. One I remember well, since my team teased me about it for months: right after I’d spent a whole hour explaining how the compiler verifies pattern match exhaustivity when there are no guards, we suffered a sudden production outage because one of my own pattern matches wasn’t exhaustive. That’s how I learned just how dangerous extractors can be.