Dev diary - 18. December 2024

Why Scala 2 Enumerations are a risk in business-critical applications

header_image

Dear Diary,

This is a friendly reminder that using Scala 2 Enumerations in business-critical applications is not a good idea. It’s a well-known problem that pattern matching on Enumerations is not exhaustive. In larger codebases, adding a new entry to the enum can cause runtime errors. Try explaining that to your manager after claiming Scala is super type-safe and that runtime errors are non-existent.

Until you migrate to Scala 3, there are a couple of options:

  1. Use a sealed trait hierarchy. The downside is that it does not provide all values out of the box.
  2. Use a library like Enumeratum (https://github.com/lloydmeta/enumeratum), which integrates well with other libraries.

Many mainstream languages don’t even address this issue and rely on awkward if/else statements. While adding an entry may not result in a runtime error, missing a business case might cost even more!

Read more

Contact us

Let's talk

I hereby consent to the processing of my personal data.