Thread Reader
Vlad

Vlad
@kopaniev

May 15
12 tweets
Tweet

1/10: Scala 3 migration Tips and Tricks. A 🧵. Important obvious: thoroughly read the migration guide and leverage scalafix for syntax updates. Will save you hours of manual work! docs.scala-lang.org/scala3/guides/

2/10: Don't rush to replace everything with new syntax! First make your codebase compile with the old syntax but using the Scala 3 compiler. The new syntax has its own rules and can cause confusing errors if you're unfamiliar, especially when mixed with the old syntax.
3/10 When replacing implicit parameters with `using`, remember that all explicit parameter passing on the call sites need the `using` keyword too! getUserInfo(userId)(using Tracing.noop) // correct
4/10: Forgetting the `using` keyword leads to cryptic errors. The compiler might highlight a completely different part of your code, making debugging frustrating. I really lost a lot if time trying to figure out what's happening.
5/10: Warning about circe: When migrating from semi-automatic derivation like `deriveConfiguredCodec `to `Codec.derived`, be careful! `Decoder.derived` doesn't accept `Configuration` as an implicit parameter — use `Decoder.derivedConfigured` instead.
6/10: You can avoid the circe issue altogether with the new derives syntax: case class MyClass(...) derives ConfiguredCodec I've almost pushed a bug to prod bc I believed that Decoder.derived would behave the same. Thanks to another issue I was able to discover it early enough.
7/10: Doobie users: watch out for giant error messages about missing Get/Put instances. In my case, AnyVal classes were the culprit—the compiler couldn't derive instances as before.
8/10: Solution for the doobie issue: convert AnyVal classes to opaque types and provide given instances in the companion object.
9/10: Faced a challenge with legacy code using shapeless tuple syntax (removed in Scala 3). Needed a way to append tuple elements and convert to case classes. First tried Scala 3's native tuple syntax, but it was incompatible with CaseClass.tupled.
10/10: After trying custom extensions for tuples (which had runtime failure risks), I found chimney library was the best solution for stitching tuples with additional values. Bonus: I even found a bug in chimney's newest release!
What migration tips have you discovered? Share below! #Scala #Scala3
Bonus #1: You can replace someContextualResource.flatMap { implicit tracing => ... } with someContextualResource.flatMap { case given TracingCtx => ... } not perfect but works, better than mixing up givens with implicits in the same file and codebase.
Vlad

Vlad

@kopaniev
SwissBorg/Scala Fanboy/FP Enthusiast
Follow on 𝕏
Missing some tweets in this thread? Or failed to load images or videos? You can try to .