Making sense of initialization order in Scala
summary
Demonstrates that Scala’s trait linearization and compiler-generated trait setters cause fields to be observed with default values or discarded values in surprising cases, with concrete examples that print zeros instead of expected constants; shows Dotty’s alternative where Dotty uses per-field init methods so fields can be final and better optimized; evaluates workarounds: lazy vals cost synchronization and can deadlock and early definitions can break assumptions; proposes forcing lazy-like init only during construction and reports Dotty experiments that exposed real code breakage.
AI-written summary · about
chapters (6)
- 0:00Start
- 6:07TRICKY EXAMPLES
- 9:09SPECIFICATION: LINEARIZATION ORDER
- 22:28ALTERNATIVE: EARLY DEFINITIONS
- 25:06DOES NOT SOLVE THE PROBLEM OF ACCESSING PARTIALLY OR NOT INITIALIZED FIELDS
- 25:42A CRAZY IDEA
related talks
45mScala 3, Type Inference and You!
49mFrom DOT to Dotty
30mDotty and types: the story so far
39mA few tips on modelling things in Scala
45mDesign Patterns in Scala
32mSingle Serving Values with Linear Types in Scala
01h 04mKeynote - What to Leave Implicit
51mOpening Keynote: New Functional Constructs in Scala 3
