Migrating a large, mature Scala 2 codebase (a Play Framework web application) to Scala 3 proved to be a generally smooth experience, with surprisingly few major hurdles. While the compiler was strict and uncovered some pre-existing issues, most migration problems were readily solvable with minor code adjustments. The new features, like enums and opaque types, offered significant improvements in type safety and code clarity. Performance saw a slight improvement, and the migration ultimately simplified the codebase, reducing boilerplate and improving maintainability. The biggest challenge was handling macros, which required waiting for compatible libraries or implementing workarounds. Overall, the author strongly recommends migrating to Scala 3, highlighting the long-term benefits over the manageable short-term effort.
Pierre Ricadat's blog post, "Scala 3 Migration: Report from the Field," details his experience migrating a production codebase, a "medium-sized" project with around 30k lines of Scala 2 code, to Scala 3. He outlines the process, highlighting both the challenges encountered and the benefits gained. The migration wasn't undertaken for the sake of novelty but driven by a practical need to upgrade dependencies, specifically the Play Framework, which had transitioned to Scala 3.
The migration process began with addressing compiler errors, which, while numerous initially, proved manageable due to clear and informative error messages from the Scala 3 compiler. Ricadat emphasizes the compiler's helpfulness in pinpointing issues and guiding the necessary code adjustments. A significant portion of the initial errors stemmed from changes in the collections library, requiring adjustments to method names and import paths. He notes the removal of CanBuildFrom
as a source of some difficulty, though the required changes were generally straightforward.
Beyond compiler errors, Ricadat encountered challenges related to macros. Specifically, he discusses difficulties with macro libraries that hadn't yet been updated for Scala 3 compatibility. This necessitated forking and adapting those libraries, a process he describes as somewhat laborious. Additionally, the migration revealed subtle differences in macro behavior between Scala 2 and 3, further complicating the adaptation process. Despite these hurdles, Ricadat expresses satisfaction with the overall experience of working with macros in Scala 3.
The blog post also delves into the benefits realized after the migration. Ricadat praises the improved type inference in Scala 3, leading to cleaner and more concise code. He highlights the new optional braceless syntax as a significant improvement in code readability and maintainability, emphasizing its positive impact on the project's overall aesthetics. Furthermore, the author appreciates the enhanced metaprogramming capabilities in Scala 3, noting its potential for future development.
The overall tone of the post is positive. While acknowledging the inherent challenges of any significant migration, Ricadat concludes that the migration to Scala 3 was a worthwhile endeavor. He emphasizes the long-term benefits of utilizing a modern and actively developed language, citing the improved developer experience and the potential for leveraging new language features in future projects. He portrays Scala 3 as a robust and mature language ready for production use, suggesting that the perceived complexities of migration are manageable and ultimately rewarding.
Summary of Comments ( 5 )
https://news.ycombinator.com/item?id=42964773
HN users generally praised the blog post for its honesty and detailed account of a real-world Scala 3 migration. Several commenters echoed the author's struggles with the IntelliJ Scala plugin and its impact on the migration process. Some highlighted the benefits of Scala 3's new features, particularly the improved type system and metaprogramming capabilities. Others discussed the challenges of community adoption and the fragmentation caused by libraries not yet supporting Scala 3. A few users questioned the overall value proposition of Scala 3, given the migration effort required. The lack of comprehensive documentation and the steep learning curve for some features were also mentioned as pain points.
The Hacker News post titled "Scala 3 Migration: Report from the Field" (linking to a blog post detailing a Scala 3 migration experience) generated several comments discussing various aspects of Scala 3 and the migration process.
Several commenters focused on the challenges and complexities involved in migrating to Scala 3. One user highlighted the difficulty of migrating large codebases, particularly those relying heavily on macros, due to the significant changes in the macro system between Scala 2 and 3. They expressed concern that the migration effort might outweigh the benefits for some projects. Another commenter echoed this sentiment, emphasizing that rewriting macros is a non-trivial task and requires significant expertise.
The discussion also touched upon build tool issues, with one commenter mentioning problems encountered with sbt during the migration process. The complexity and sometimes opaque nature of sbt configurations were cited as contributing factors to these difficulties.
Some comments addressed specific features of Scala 3. One user praised the new enums and how they improve type safety, though acknowledging that migrating them can be cumbersome. Another appreciated the enhanced metaprogramming capabilities and the overall direction Scala 3 is taking.
One commenter questioned the necessity and advantages of the implicit resolution changes in Scala 3, suggesting they may lead to more verbose code without significant improvements in clarity. This spurred a brief discussion about the trade-offs involved in the new implicit system.
The overall tone of the comments was a mix of cautious optimism and pragmatic concern. While acknowledging the potential benefits of Scala 3's improvements, many commenters recognized the substantial effort required for migration and the challenges that may arise during the process. Several expressed a desire for more tooling and community support to facilitate smoother transitions. The discussion underscored the fact that while Scala 3 offers compelling new features, the migration path is not without its hurdles.