Skip to content

Commit 6e01289

Browse files
Apply suggestions from code review
Co-authored-by: Anatolii Kmetiuk <[email protected]>
1 parent bec506f commit 6e01289

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

blog/_posts/2023-12-08-migration-to-scala-3.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ title: "Scala 3: My migration journey"
66
description: I want to share my journey from Scala 2 to Scala 3 and discuss migration to Scala 3
77
---
88

9-
## Implicit context
10-
11-
Before doing any actual personal work, based on the internet discussions, I had an impression that switching to Scala 3 would be quite painful — in practice, it was pretty straightforward.
9+
I want to share my journey from Scala 2 to Scala 3 and discuss migration to Scala 3.
1210

13-
In the retrospect, this was the case because I (and my team) fall into the following buckets:
11+
## Implicit context
1412

15-
- Don’t use IntelliJ;
16-
- Don’t use macros;
17-
- Use Typelevel stack.
13+
I am just a software engineer. Before doing any actual personal work, based on the internet discussions, I had an impression that switching to Scala 3 would be quite painful — in practice, it was pretty straightforward.
1814

19-
It wouldn’t be as smooth if any of these were different.
15+
In retrospect, our experience was determined by the technology stack and tools that I (and my team) use: microservices, Typelevel stack, VS Code with Metals, and, most importantly, no macros. It might not be as smooth if any of these wasn't the case.
2016

2117
Let’s start in my world first, follow the primary migration steps, and then talk about what to do if your setup and stack differ.
2218

@@ -32,7 +28,7 @@ Should you rewrite one service at a time? In what order? Or should you leave the
3228

3329
It’s also an excellent time to discuss the benefits and trade-offs. And keep it fair. For example, if you just want a new syntax, is it worth disturbing an old service that hasn’t been touched in years? Well, it’s up to you to decide.
3430

35-
*We decided to write all the new services in Scala 3 (where most of the future work will happen) and keep the rest. Consequently, onboarding new devs without prior Scala experience is one of my biggest challenges.* W*hen they switch from Scala 3 service to Scala 2, they bump into hurdles — some of the “intuitive” concepts don’t work as expected anymore. This requires more explanation; they seem to have to learn some things twice.*
31+
*We decided to write all the new services in Scala 3 (where most of the future work will happen) and keep the rest. Consequently, onboarding new devs without prior Scala experience is one of my biggest challenges. When they switch from Scala 3 service to Scala 2, they bump into hurdles — some of the “intuitive” concepts don’t work as expected anymore. This requires more explanation; they seem to have to learn some things twice.*
3632

3733
Okay, we defined what migration means, but how exactly do we go about it?
3834

@@ -50,11 +46,13 @@ Other questions you might need to consider:
5046

5147
Thanks to the [interoperability](https://docs.scala-lang.org/scala3/guides/migration/compatibility-source.html) between Scala 3 and Scala 2.13, it might be more accessible or crucial to upgrade to Scala 2.13 first. You have to keep this in mind.
5248

53-
*By this point, we knew that all our services were on 2.13; we knew how many internal libraries needed to be used from both Scala versions and what external libraries had no Scala 3 support: what is the status, what is missing, and what can we do to deal with it. For example, a couple of libraries got a Scala 3 release by the time we were done with the investigation, and one `circe` ”extras” library was replaced with two lines of boilerplate.*
49+
*By this point, we knew that all our services were on 2.13; we knew how many internal libraries needed to be used from both Scala versions and what external libraries had no Scala 3 support: what the status is, what is missing, and what we can do to deal with it. For example, a couple of libraries got a Scala 3 release by the time we were done with the investigation, and one `circe` ”extras” library was replaced with two lines of boilerplate.*
5450

5551
## Step 2. Draw the rest of the owl
5652

57-
After all the meetings and/or writings comes the time to do the actual work. When you have concrete questions or action items, remember that [Scala 3 migration guides](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html) are your friends. For example, it covers how to port compiler options and sbt projects. Great reference resource.
53+
After all the meetings and/or writings comes the time to do the actual work. When you have concrete questions or action items, remember that [Scala 3 migration guides](https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html) are your friends. For example, it covers how to port compiler options and build configurations. Great reference resource.
54+
55+
> Note that you can find further help from the community on [Scala Discord](https://discord.com/invite/scala).
5856
5957
We don’t have to go into these details right now. Instead, let’s talk about the bigger picture and a few other things to remember.
6058

@@ -70,7 +68,7 @@ There are multiple ways of sharing a library between Scala 2 and Scala 3 service
7068

7169
Imagine you have an internal library (e.g., auth-handling, specific DB-connector, peculiar API) used by your existing Scala 2 services that will also be used by Scala 3 services. If your library on Scala 2 uses the `ducks` library and your Scala 3 application uses `ducks` as well, you get two conflicting versions `ducks_2.13` and `ducks_3`.
7270

73-
To solve this, you can cross-publish your library to both versions by adding one line to your build:
71+
To solve this, with sbt, you can cross-publish your library to both versions by adding one line to your build:
7472

7573
```scala
7674
+ crossScalaVersions := List("2.13.12", "3.3.1")
@@ -97,16 +95,25 @@ Otherwise, you might need [to help them](https://docs.scala-lang.org/contribute/
9795
### Dealing with plugins
9896

9997
Similar to dependencies, some plugins stay working, and some — are redundant and can be dropped.
100-
For instance, the first plugin I was happy to retire was `better-monadic-for`, because Scala 3 already gives me better for-comprehensions:
98+
99+
For instance, the first plugin I was happy to retire was `better-monadic-for`, because Scala 3 already gives me better for-comprehensions. For example, we can define implicit values inside for-comprehensions:
101100

102101
```scala
102+
// Scala 3
103103
for
104-
// Can't do this in vanilla Scala 2:
105104
given Logger[IO] <- makeLoggerOrSomething
106105
result <- doX
107106
yield doY(result)
108107
```
109108

109+
```scala
110+
// Scala 2 with better-monadic-for
111+
for
112+
implicit0(logger: Logger[IO]) <- makeLoggerOrSomething
113+
result <- doX
114+
yield doY(result)
115+
```
116+
110117
The second one is `kind-projector`. Scala 3 has [built-in type lambda syntax](https://docs.scala-lang.org/scala3/reference/new-types/type-lambdas-spec.html) and [kind-projector compatible syntax](https://docs.scala-lang.org/scala3/reference/changed-features/wildcards.html).
111118

112119
> For even more information, see the [Kind Projector Migration](https://docs.scala-lang.org/scala3/guides/migration/plugin-kind-projector.html) guide.
@@ -131,7 +138,7 @@ Scala-3-rewrite allows you to get rid of the old workarounds as well as challeng
131138

132139
To me, using VS Code with Metals and Scala 3 doesn’t feel different from using these with Scala 2 a couple of years ago. And it’s only getting better.
133140

134-
[IntelliJ IDEA 2023.2](https://blog.jetbrains.com/scala/2023/07/26/intellij-scala-plugin-2023-2-is-out/) brought enhanced Scala 3 support, and the team is constantly working on improvements. [Metals](https://scalameta.org/metals/) has regular [releases](https://scalameta.org/metals/blog/) driven by [Scala Center](https://scala.epfl.ch/)[VirtusLab](https://virtuslab.com/), and contributors from the community. So, if you haven’t recently tried either, now is a good time.
141+
[IntelliJ IDEA 2023.2](https://blog.jetbrains.com/scala/2023/07/26/intellij-scala-plugin-2023-2-is-out/) brought enhanced Scala 3 support, and the team is constantly working on improvements ([IntelliJ IDEA 2023.3](https://blog.jetbrains.com/scala/2023/12/07/intellij-scala-plugin-2023-3-is-out/) was released just when I was writing this)[Metals](https://scalameta.org/metals/) has regular [releases](https://scalameta.org/metals/blog/) driven by [Scala Center](https://scala.epfl.ch/)[VirtusLab](https://virtuslab.com/), and contributors from the community. So, if you haven’t recently tried either, now is a good time.
135142

136143
### What to do about macros (and other issues)
137144

0 commit comments

Comments
 (0)