Estimate project
← All posts

A Scala journey: from Java generics to higher-kinded types

Learn how our guest became a Scala programmer – from his first steps with the language to his views today.

5 min read
ScalaFunctional Programming20YearsOfScala

Celebrate Scala’s 20th birthday with us in 2024! We’ve asked a number of Scala experts to tell us their remarkable Scala Stories. Our guest works as a Lead Software Engineer.

When did you first come across Scala, and what was your impression?

I enrolled in the “Functional Programming Principles in Scala” MOOC from EPFL. Overall, my impression was: “This is really enjoyable!”

Describe a moment when you thought, “Aha! Scala is awesome!” Which Scala features and capabilities gave you that feeling?

Most likely when higher-kinded types finally clicked for me, although that definitely took more than a moment! 🙂

It dawned on me that if you follow Java generics through to their “logical consequences”, you naturally end up with higher-kinded types.

Even today, only a handful of industrial-grade languages support higher-kinded types, which makes them one of Scala’s distinguishing features.

In what way has Scala shaped how you tackle programming problems?

Having a Java background, my first instinct was to start drawing inheritance hierarchies in my head. In doing so, I was unknowingly narrowing the space of possible solutions.

Scala showed me that, in most cases, reasoning in terms of functions and (algebraic) data types is the more productive way.

What’s more, since that lesson I’ve stayed alert to other things I could be overlooking. It also shattered my naive assumption that (statically typed) programming languages are essentially interchangeable, and that any worthwhile language feature would surely have made it into the Java language by now. 😂

When I later stumbled upon the Dijkstra quote below, I felt I understood exactly what he meant:

The tools we work with deeply (and slyly!) shape our habits of thought, and thus our capacity to think. – Edsger W. Dijkstra

If you could add one new feature to Scala, which would it be, and how would developers benefit?

Scala has gained lots of new features lately. In my view, the priority now should be making the existing ones rock solid and able to scale to arbitrarily complex scenarios. Whether that’s polymorphic function types, match types and abstracting over arity, kind-polymorphism, meta-programming, or the perennial GADT pattern matching.

If I had to pick one new feature, it would be compile-time evaluation of arbitrary syntax trees (i.e. TASTy trees). In a way, this also just means making an existing feature (.valueOrAbort) scale to a complex use case, but it’s significant enough to count as a new feature. It would considerably expand the range of checks and transformations possible at compile time, ruling out even more illegal programs.

Share a case where Scala turned out to be a game-changer in a real-world project

I’ve seen a small team of 3-4 seasoned Scala developers ship features for several years with a very low bug rate. I’ve also seen (Java, Node.js) projects of similar size looked after by a team about ~3x larger, which could barely keep the project going in maintenance mode, with everyone afraid to touch anything.

How has the Scala community shaped your programming path? Any memorable interactions or stories of support?

When you’re a beginner and ask a sincere, if naive, question, people treat you seriously.

When you submit your first modest pull request to an OSS project, people treat you seriously.

It makes you feel that your work counts.

Were there any funny or embarrassing moments while you were learning Scala?

With my Java background, I already knew generic programming, didn’t I? Then I stumbled on a library called shapeless, which described itself as a “generic programming library for Scala”. Surely, I thought, that was a joke. I don’t need a library for generic programming! Then I looked closer. And wow, had I been missing out!

I already knew functional programming, didn’t I? I’d finished the MOOC! Then I stumbled on a library called scalaz, which described itself as a “Scala library for functional programming.” Clearly, that was a joke. I don’t need a library for functional programming! Then I looked closer. And wow, had I been missing out!

What would you recommend to someone who is just getting started with Scala?

Picking up Scala solely on the job probably won’t be the most effective route. Scala is a pluralistic language that can host many different styles, idioms, degrees of type safety, and levels of abstraction. That’s its unique strength. At the same time, understanding a codebase that mixes styles, mirroring the team’s own stages of development, may be more than you can digest at once – unless your mentor shapes and refines the tasks so that they essentially form a tutorial made just for you. Since that’s unlikely, find a well-crafted tutorial somewhere else (e.g., the MOOC mentioned above or one of the many other introductory resources) to get going. After that, follow your own curiosity.

Where do you see Scala heading over the next decade?

I anticipate a renewed emphasis on Scala’s core strength: being a scalable language.

Scala can scale alongside your project’s complexity, from a one-off script to an intricate distributed system.

Scala can scale alongside growing demands for static guarantees, from “let’s run it and find out” to “it compiles, ship it!”

Scala can scale alongside the level of abstraction, from shuffling bytes to accurately modelling the domain.

Scala can scale alongside your learning, letting beginners get in easily (with the right introduction), without imposing a low ceiling on your development or patronizing the experts.

The industry will always go through hype cycles and turbulent periods, but even then – or precisely then – scalability stays a universally valued quality in a language.