Why Scala: After the Hype

11/03/2022

After the Hype

Hype in the realm of software development primarily affects whether programming languages and tools ever obtain a significant foothold among users and ultimately in industry or academia. In my last article, I discussed zealotry; And one might consider hype and zealotry analogous to campaigning for some elected official. Every candidate, or programming language, has a catchphrase. And often choosing the wrong catchphrase can have disastrous effects. In these situations, something amazing will likely be overlooked. This was the unfortunate case for Scala.

Better Java is Dead; Long Live Better Java!

Occasionally one may hear something about Scala. However, it's usually relegated to the realm of "other languages". If you ask someone who's casually aware of Scala's existence about it, they'll say, "it was designed to be better Java." That title has since been taken by Kotlin. This is where hype completely failed Scala. In my opinion, Scala isn't better Java. The origins of Scala do suggest that "being a better Java" but in time it's significantly expanded beyond that original definition. In a sense that's the reason it failed at "being a better Java", which is why it was usurped in that role by Kotlin.

What Remains

None of the above is to say, however, that Scala should be counted out. In fact, after significant evaluation, I believe it's an amazing general purpose language that has been overlooked because of a poorly formed consensus. But it all comes back to the question of "why?". This question has haunted Scala since its inception, but hopefully this article may help to answer some of those questions for you.

What is Scala

If asked to describe Scala, I would say, "Scala is a language designed with an emphasis on scalability, allowing users to start with a script and transition to a maintainable enterprise solution. On a more technical level, it's a statically typed language featuring type inference that supports both advanced object-oriented programming and functional programming aspects. This in combination with amazing compatibility for the existing Java ecosystem allows users to write less boilerplate. Ultimately, this enables users to rapidly prototype and then scale solutions to maintainability and reliability."

I'll admit that's a lot, so I'll try to break that down. First, let me consider two languages as alternatives, Python and C#. Let's say you want to do some quick prototyping for a feature that needs to go into your enterprise-grade application. Here are the typical steps:

  1. Pick your favorite dynamically typed scripting language, probably Python. You now begin prototyping your feature.

  2. You've now prototyped said feature in Python. Even if you could scale the solution, you probably shouldn't Python has type behavior at scale that can make tracking down a type coercion bug an absolute nightmare in a large codebase.

  3. So we now need to translate our existing solution into our enterprise-grade language of choice, C#. Sometimes this can have drastic effects on the simplicity or readability of the proposed solution. You'll lose valuable working time resolving these incompatibilities.

Now consider the similar process for Scala:

  1. The functional aspects of Scala combined with support for Scala scripts and access to large a Java ecosystem make scripting viable. So we build our prototype while still not requiring the explicit typing of every variable you use.

  2. Now that your code works, all you have to do is copy and paste it into your Scala project or compile it into a Java class for use in existing Java systems. And this is the really cool part in my opinion. Pattern-matching, multiple trait inheritance, and JVM interoperability are all really cool, but the absence of the translation step is where the beauty of Scala truly lies. Scala really is the general-purpose scalable language.

Still interested?

So the point of this article, was to discuss Scala's defining feature, but there's some other really cool things that are just icing on top of a very delicious cake. They may not be selling points, but if you're already interested, they're really cool to do more research on:

  • Scala isn't limited to the JVM, it also has a native machine code compiler and JavaScript transpiler.

  • Ammonite is an amazing tool that powers Scala scripts, you can use make an self-executable scripts even with imports using #!/usr/bin/env amm

  • Scala is pretty well-known in the machine learning and big data realm, mostly because of its use in Apache Kafka, the backend of LinkedIn, and it's support by Apache Spark.

  • There's a project called Slinky, that let's you write React apps in Scala. And it has full interoperability with normal JavaScript React components.

  • The IDE support provided by the JetBrains IntelliJ IDEA and the Metals Language Server for VS Code are top-notch.

  • For-comprehensions are like python's generators on steroids. It's an absolute blast to use them.

The above is a selection of exciting additional projects and features you can really explore once you become familiar with Scala itself.

TL; DR

The truth is, it's hard to develop a general-purpose programming language that will see significant adoption. Most people are comfortable with what they know and won't consider switching unless you can say this language does some domain of work better, e.g. Kotlin vs Java for Android development. Scala isn't a better Java. It's significant in its own right. In my opinion, project scalability is what Scala does better. It's not domain specific and honestly if another language came along and did it, better, I'd say Scala is actually done better by XYZ. But for now, you shouldn't count Scala out. In my opinion, it has a lot of unrecognized potential.