Scala default visibility: missing private‑by‑default enforcement
0 reputation · 04 Aug 2025, 00:13 UTC
In Scala, any class member without an explicit private, protected, or package‑specific modifier is public by default, meaning it is visible from any other code in the same or a different package.
Despite this, the Scala community has debated for years whether the language should adopt a private‑by‑default model to reduce accidental public APIs, but no decision has been finalized.
Developers therefore rely on conventions or custom linting tools to enforce stricter encapsulation, which can be inconsistent across projects and build pipelines.
Without a language‑level or compiler‑level enforcement, there is a risk that internal helpers or experimental fields become part of the public contract, complicating refactoring and versioning.
What mechanisms are currently available to warn about or block default‑public members? How can a project configure the compiler or tooling to enforce a private‑by‑default discipline? Are there active proposals to change the default visibility, and what would be the migration path?