In this talk, we are going to explain what is a primitive obsession and why it is a bad smell in the code. Instead of making case class full of strings:
case class Person(firstName: String, middleName: String, lastName: String)
we will show how to create separate (new) types for each of them and make this case class much more type-safe:
case class Person(firstName: FirstName, middleName: MiddleName, lastName: LastName)
There are several ways how this can be accomplished in Scala. We have value classes and tagged types available in Scala 2, as well as opaque types in Scala 3. We will show how to use them and what are pros and cons of each of them. We will also show libraries that can help in creating new types and reducing the amount of the boilerplate.
We will present in more detail Monix's Newtypes and kebs, which are libraries that can be used in Scala 2 and 3. We will also show or mention others, e. g. refined and Mazboot.