Discuss the use of Scala's experimental features in production code.
Instruction: Explain the considerations and implications of using Scala's experimental features in production environments.
Updated
Official answer
Identify the exact feature, compiler version and stability policy before making a production decision. An experimental language feature, a nightly compiler and a library API marked @experimental are related risks, but are not interchangeable labels.
In Scala 3, @experimental marks definitions without guaranteed backward source or binary compatibility and restricts their use to experimental scopes. The -experimental compiler flag makes top-level definitions experimental, which also affects dependent projects. Enabling a flag is not a compatibility guarantee or a purely local implementation choice for a published library.
Document the concrete benefit and compare a stable implementation. If the experimental feature is justified, constrain its use, pin the toolchain and dependencies, and verify compiler/plugin/IDE support. Avoid exposing experimental types or behavior through a widely consumed API unless consumers explicitly accept the same constraints.
Test the relevant failure modes, compilation of downstream consumers, upgrade behavior, performance and serialized/persisted data compatibility. Keep a reproducible prior build and a migration or fallback path; reverting source code alone may not undo a data-format change.
Monitor error rates, latency, resource use and the behavior affected by the feature. A change in daily active users does not isolate a compiler feature's effect. Record an owner and a review point for stabilization, replacement or removal. Testing reduces uncertainty but cannot turn an experimental compatibility policy into a stable one.
Sources
Scala 3 experimental definitions; Scala 3 binary compatibility; nightly releases.